public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer)) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } if (!Alive) { return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = World.PlayerByUid(entityplr.PlayerUID); player.InventoryManager.OpenInventory(Inventory); tradingWith = entityplr; if (World.Side == EnumAppSide.Client) { if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true) { dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI); dlg.TryOpen(); dlg.OnClosed += () => tradingWith = null; } talkUtil.Talk(EnumTalkType.Meet); } if (World.Side == EnumAppSide.Server) { // Make the trader walk towards the player AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().taskManager; tmgr.StopTask(typeof(AiTaskWander)); AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr); if (task.TargetReached()) { tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1); } else { tmgr.ExecuteTask(task, 1); } AnimManager.StopAnimation("idle"); AnimManager.StartAnimation(new AnimationMetaData() { Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000 }); } }
public override void OnInteract(EntityAgent byEntity, IItemSlot slot, Vec3d hitPosition, int mode) { if (mode != 1 || !(byEntity is EntityPlayer)) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = World.PlayerByUid(entityplr.PlayerUID); player.InventoryManager.OpenInventory(Inventory); tradingWith = entityplr; if (World.Side == EnumAppSide.Client) { if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5) { dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI); dlg.TryOpen(); dlg.OnClosed += () => tradingWith = null; } talkUtil.Talk(EnumTalkType.Meet); } if (World.Side == EnumAppSide.Server) { // Make the trader walk towards the player AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().taskManager; tmgr.StopTask(typeof(AiTaskWander)); AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr); if (task.TargetReached()) { tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1); } else { tmgr.ExecuteTask(task, 1); } } }
public override void OnInteract(EntityAgent byEntity, ItemSlot slot, Vec3d hitPosition, EnumInteractMode mode) { if (mode != EnumInteractMode.Interact || !(byEntity is EntityPlayer)) { base.OnInteract(byEntity, slot, hitPosition, mode); return; } if (!Alive) { return; } EntityPlayer entityplr = byEntity as EntityPlayer; IPlayer player = World.PlayerByUid(entityplr.PlayerUID); tradingWith = entityplr; if (World.Side == EnumAppSide.Client) { ICoreClientAPI capi = (ICoreClientAPI)Api; if (tradingWith.Pos.SquareDistanceTo(this.Pos) <= 5 && dlg?.IsOpened() != true) { // Will break all kinds of things if we allow multiple concurrent of these dialogs if (capi.Gui.OpenedGuis.FirstOrDefault(dlg => dlg is GuiDialogTrader && dlg.IsOpened()) == null) { capi.Network.SendEntityPacket(this.EntityId, 1001); player.InventoryManager.OpenInventory(Inventory); dlg = new GuiDialogTrader(Inventory, this, World.Api as ICoreClientAPI); dlg.TryOpen(); } else { capi.TriggerIngameError(this, "onlyonedialog", Lang.Get("Can only trade with one trader at a time")); } } else { // Ensure inventory promptly closed server-side if the client didn't open the GUI capi.Network.SendPacketClient(capi.World.Player.InventoryManager.CloseInventory(Inventory)); } talkUtil.Talk(EnumTalkType.Meet); } if (World.Side == EnumAppSide.Server) { // Make the trader walk towards the player AiTaskManager tmgr = GetBehavior <EntityBehaviorTaskAI>().TaskManager; tmgr.StopTask(typeof(AiTaskWander)); AiTaskGotoEntity task = new AiTaskGotoEntity(this, entityplr); if (task.TargetReached()) { tmgr.ExecuteTask(new AiTaskLookAtEntity(this, entityplr), 1); } else { tmgr.ExecuteTask(task, 1); } AnimManager.StartAnimation(new AnimationMetaData() { Animation = "welcome", Code = "welcome", Weight = 10, EaseOutSpeed = 10000, EaseInSpeed = 10000 }); AnimManager.StopAnimation("idle"); } }