Implemented code for custom npc merchants. Pretty simple actually and the result is very pleasing.

This commit is contained in:
2018-03-17 04:39:46 -07:00
parent 07757dac1f
commit f8517e37c3
4 changed files with 53 additions and 3 deletions

View File

@ -108,7 +108,11 @@ namespace CustomNPCFramework
private void SaveEvents_LoadChar(object sender, EventArgs e)
{
ExtendedNPC myNpc3 = assetPool.generateNPC(Genders.female, 0, 1);
npcTracker.addNewNPCToLocation(Game1.getLocationFromName("BusStop", false), myNpc3);
MerchantNPC merch = new MerchantNPC(new List<Item>()
{
new StardewValley.Object(475,999)
}, myNpc3);
npcTracker.addNewNPCToLocation(Game1.getLocationFromName("BusStop", false), merch);
}
public void initializeExamples()

View File

@ -65,6 +65,7 @@
<Compile Include="Framework\ModularNPCS\Sprite.cs" />
<Compile Include="Framework\NPCNames.cs" />
<Compile Include="Framework\NPCS\ExtendedNPC.cs" />
<Compile Include="Framework\NPCS\MerchantNPC.cs" />
<Compile Include="Framework\Utilities\NPCTracker.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@ -49,7 +49,10 @@ namespace CustomNPCFramework.Framework.NPCS
this.Portrait = (Texture2D)null;
this.portraitInformation = null;
this.spriteInformation = sprite;
this.spriteInformation.setCharacterSpriteFromThis(this);
if (this.spriteInformation != null)
{
this.spriteInformation.setCharacterSpriteFromThis(this);
}
this.swimming = false;
}
@ -57,7 +60,10 @@ namespace CustomNPCFramework.Framework.NPCS
{
this.characterRenderer = null;
this.portraitInformation = portrait;
this.portraitInformation.setCharacterPortraitFromThis(this);
if (this.portraitInformation != null)
{
this.portraitInformation.setCharacterPortraitFromThis(this);
}
this.spriteInformation = sprite;
this.spriteInformation.setCharacterSpriteFromThis(this);
this.swimming = false;

View File

@ -0,0 +1,39 @@
using CustomNPCFramework.Framework.ModularNPCS;
using CustomNPCFramework.Framework.ModularNPCS.ModularRenderers;
using Microsoft.Xna.Framework;
using StardewValley;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CustomNPCFramework.Framework.NPCS
{
class MerchantNPC: ExtendedNPC
{
public List<Item> stock;
public MerchantNPC(List<Item> Stock, Sprite sprite, BasicRenderer renderer,Vector2 position,int facingDirection,string name): base(sprite,renderer,position,facingDirection,name)
{
this.stock = Stock;
}
public MerchantNPC(List<Item> Stock, ExtendedNPC npcBase): base(npcBase.spriteInformation, npcBase.portraitInformation, npcBase.position, npcBase.facingDirection, npcBase.name)
{
this.stock = Stock;
}
public override bool checkAction(StardewValley.Farmer who, GameLocation l)
{
if (Game1.activeClickableMenu == null)
{
Game1.activeClickableMenu = new StardewValley.Menus.ShopMenu(this.stock);
return true;
}
else
{
return base.checkAction(Game1.player, Game1.player.currentLocation);
}
}
}
}