Beispiel #1
0
        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
                });
            }
        }
Beispiel #2
0
        public override bool ShouldExecute()
        {
            if (entity.World.Rand.NextDouble() > 0.03)
            {
                return(false);
            }
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            if (cooldownUntilTotalHours > entity.World.Calendar.TotalHours)
            {
                return(false);
            }
            if (whenInEmotionState != null && !entity.HasEmotionState(whenInEmotionState))
            {
                return(false);
            }
            if (whenNotInEmotionState != null && entity.HasEmotionState(whenNotInEmotionState))
            {
                return(false);
            }

            targetEntity = (EntityButterfly)entity.World.GetNearestEntity(entity.ServerPos.XYZ, seekingRange, seekingRange, (e) => {
                if (!e.Alive || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                if (e is EntityButterfly)
                {
                    return(true);
                }

                return(false);
            });

            if (targetEntity != null)
            {
                chaseTime = (float)entity.World.Rand.NextDouble() * 7 + 6;
                targetPos.Set(targetEntity.ServerPos.X, targetEntity.ServerPos.Y, targetEntity.ServerPos.Z);

                // Tell the other butterfly to chase us
                AiTaskManager        manager   = targetEntity.GetBehavior <EntityBehaviorTaskAI>().taskManager;
                AiTaskButterflyChase othertask = manager.GetTask <AiTaskButterflyChase>();
                othertask.targetEntity = this.entity as EntityButterfly;
                othertask.targetPos.Set(entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z);
                othertask.chaseTime = (float)entity.World.Rand.NextDouble() * 7 + 6;

                manager.ExecuteTask <AiTaskButterflyChase>();
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        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);
                }
            }
        }
Beispiel #4
0
        public bool TryBeginMilking()
        {
            lastIsMilkingStateTotalMs = entity.World.ElapsedMilliseconds;

            bhmul = entity.GetBehavior <EntityBehaviorMultiply>();
            // Can not be milked when stressed (= caused by aggressive or fleeing emotion states)
            float stressLevel = entity.WatchedAttributes.GetFloat("stressLevel");

            if (stressLevel > 0.1)
            {
                if (entity.World.Api is ICoreClientAPI capi)
                {
                    capi.TriggerIngameError(this, "notready", Lang.Get("Currently too stressed to be milkable"));
                }
                return(false);
            }

            // Can only be milked for 21 days after giving birth
            double daysSinceBirth = Math.Max(0, entity.World.Calendar.TotalDays - bhmul.TotalDaysLastBirth);

            if (bhmul != null && daysSinceBirth >= lactatingDaysAfterBirth)
            {
                return(false);
            }

            // Can only be milked once every day
            if (entity.World.Calendar.TotalHours - lastMilkedTotalHours < entity.World.Calendar.HoursPerDay)
            {
                return(false);
            }
            int generation = entity.WatchedAttributes.GetInt("generation", 0);

            aggroChance = Math.Min(1 - generation / 3f, 0.95f);
            aggroTested = false;
            clientCanContinueMilking = true;


            if (entity.World.Side == EnumAppSide.Server)
            {
                AiTaskManager tmgr = entity.GetBehavior <EntityBehaviorTaskAI>().TaskManager;
                tmgr.StopTask(typeof(AiTaskWander));
                tmgr.StopTask(typeof(AiTaskSeekEntity));
                tmgr.StopTask(typeof(AiTaskSeekFoodAndEat));
                tmgr.StopTask(typeof(AiTaskStayCloseToEntity));
            }
            else
            {
                if (entity.World is IClientWorldAccessor cworld)
                {
                    milkSound?.Dispose();
                    milkSound = cworld.LoadSound(new SoundParams()
                    {
                        DisposeOnFinish = true,
                        Location        = new AssetLocation("sounds/creature/sheep/milking.ogg"),
                        Position        = entity.Pos.XYZFloat,
                        SoundType       = EnumSoundType.Sound
                    });

                    milkSound.Start();
                }
            }

            return(true);
        }
Beispiel #5
0
 public EntityBehaviorTaskAI(Entity entity) : base(entity)
 {
     taskManager = new AiTaskManager(entity);
 }
        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");
            }
        }
 static EntityButterfly()
 {
     AiTaskManager.RegisterTaskType("butterflywander", typeof(AiTaskButterflyWander));
 }