public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { base.Initialize(properties, api, InChunkIndex3d); if (Inventory == null) { Inventory = new InventoryTrader("traderInv", "" + EntityId, api); } if (api.Side == EnumAppSide.Server) { try { string json = Properties.Server.Attributes["tradeProps"].ToJsonToken(); TradeProps = new JsonObject(json).AsObject <TradeProperties>(); } catch (Exception e) { api.World.Logger.Error("Failed deserializing TradeProperties for trader {0}, exception logged to verbose debug", properties.Code); api.World.Logger.VerboseDebug("Failed deserializing TradeProperties: {0}", e); api.World.Logger.VerboseDebug("================="); api.World.Logger.VerboseDebug("Tradeprops json:"); api.World.Logger.VerboseDebug("{0}", Properties.Server.Attributes["tradeProps"].ToJsonToken()); } if (OutfitCodes == null) { OutfitCodes = api.ModLoader.GetModSystem <TraderOutfits>().GetRandomOutfit(); } } else { talkUtil = new TalkUtil(api as ICoreClientAPI, this); } try { Inventory.LateInitialize("traderInv-" + EntityId, api, this); } catch (Exception e) { api.World.Logger.Error("Failed initializing trader inventory. Will recreate. Exception logged to verbose debug"); api.World.Logger.VerboseDebug("Failed initializing trader inventory. Will recreate. Exception {0}", e); WatchedAttributes.RemoveAttribute("traderInventory"); Inventory = new InventoryTrader("traderInv", "" + EntityId, api); Inventory.LateInitialize("traderInv-" + EntityId, api, this); RefreshBuyingSellingInventory(); } (AnimManager as TraderAnimationManager).Personality = this.Personality; this.Personality = this.Personality; // to update the talkutil }
public override void Initialize(EntityProperties properties, ICoreAPI api, long InChunkIndex3d) { base.Initialize(properties, api, InChunkIndex3d); if (Inventory == null) { Inventory = new InventoryTrader("traderInv", "" + EntityId, api); } if (api.Side == EnumAppSide.Server) { try { string json = Properties.Server.Attributes["tradeProps"].ToJsonToken(); TradeProps = new JsonObject(json).AsObject <TradeProperties>(); } catch (Exception e) { api.World.Logger.Error("Failed deserializing TradeProperties, exception logged to verbose debug"); api.World.Logger.VerboseDebug("Failed deserializing TradeProperties: " + e); } } else { talkUtil = new TalkUtil(api as ICoreClientAPI, this); } try { Inventory.LateInitialize("traderInv-" + EntityId, api, this); } catch (Exception e) { api.World.Logger.Error("Failed initializing trader inventory. Will recreate. Exception logged to verbose debug"); api.World.Logger.VerboseDebug("Failed initializing trader inventory. Will recreate. Exception {0}", e); WatchedAttributes.RemoveAttribute("traderInventory"); Inventory = new InventoryTrader("traderInv", "" + EntityId, api); Inventory.LateInitialize("traderInv-" + EntityId, api, this); RefreshBuyingSellingInventory(); } }