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); } } }