Esempio n. 1
0
        public override bool ShouldExecute()
        {
            EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>();

            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (failureTime > entity.World.ElapsedMilliseconds || cooldownUntilMs > entity.World.ElapsedMilliseconds || !prog.CheckArea() || !CanPlant(entity.LeftHandItemSlot?.Itemstack?.Collectible))
            {
                return(false);
            }

            targetPoi = porregistry.GetNearestPoi((prog.workArea.End + prog.workArea.Start) / 2, (float)(prog.workArea.Length + prog.workArea.Height + prog.workArea.Width), (poi) =>
            {
                if (prog.workArea.ContainsOrTouches(poi.Position) && poi is BlockEntityFarmland && world.BlockAccessor.GetBlock(poi.Position.AsBlockPos).Replaceable > 9500)
                {
                    return(true);
                }


                return(false);
            });

            return(targetPoi != null);
        }
Esempio n. 2
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant || !prog.CheckArea())
            {
                return(false);
            }

            entityUtil.WalkEntities((prog.workArea.Start + prog.workArea.End) / 2, prog.workArea.Length + prog.workArea.Height + prog.workArea.Width, (ent) =>
            {
                if (!prog.workArea.ContainsOrTouches(ent.ServerPos.XYZ) || ent.GetBehavior <EntityBehaviorProgram>() == null)
                {
                    return(true);
                }
                EntityBehaviorHealth bh = ent.GetBehavior <EntityBehaviorHealth>();
                if (bh == null || bh.Health >= bh.MaxHealth)
                {
                    return(true);
                }

                targetEntity = ent;
                return(false);
            });

            return(targetEntity != null);
        }
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null)
            {
                return(false);
            }
            if (prog.dormant || !entity.LeftHandItemSlot.Empty || prog?.CheckChest() != true || prog.workStack == null || (onlyOnGuard && !prog.CheckArea()))
            {
                return(false);
            }
            Block check = world.BlockAccessor.GetBlock(prog.workChest);

            if (check != null && check.Code.Path.Contains("translocatorchest"))
            {
                if (!prog.TakeFromChest())
                {
                    failureTime = entity.World.ElapsedMilliseconds + TemporalHackerConfig.Loaded.BotFailureCooldownMs;
                }
                else
                {
                    prog.ConsumeEnergy(1);
                }
                return(false);
            }

            targetPos = prog.workChest.ToVec3d();


            return(targetPos != null);
        }
Esempio n. 4
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (!(entity.LeftHandItemSlot?.Itemstack?.Collectible.MatterState == EnumMatterState.Liquid) || prog.CheckBarrel() != true)
            {
                return(false);
            }
            Block check = world.BlockAccessor.GetBlock(prog.workBarrel);

            if (check != null && check.Code.Path.Contains("translocatorbarrel"))
            {
                if (!prog.PutInBarrel(entity.LeftHandItemSlot))
                {
                    failureTime = entity.World.ElapsedMilliseconds + TemporalHackerConfig.Loaded.BotFailureCooldownMs;
                }
                else
                {
                    prog.ConsumeEnergy(3);
                }
                return(false);
            }

            targetPos = prog.workBarrel.ToVec3d();


            return(targetPos != null);
        }
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (!prog.CheckArea() || prog.workPoint == null)
            {
                return(false);
            }
            if (entity.ServerPos.DistanceTo(prog.workPoint.ToVec3d()) <= minDist)
            {
                return(false);
            }

            targetPos = prog.workPoint.ToVec3d();


            return(targetPos != null);
        }
Esempio n. 6
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant || !prog.CheckArea())
            {
                return(false);
            }
            if (entity.LeftHandItemSlot.Itemstack?.Collectible?.CombustibleProps?.BurnDuration == null || entity.LeftHandItemSlot.Itemstack?.Collectible?.CombustibleProps?.BurnTemperature < 200)
            {
                return(false);
            }

            entityUtil.WalkEntities((prog.workArea.Start + prog.workArea.End) / 2, prog.workArea.Length + prog.workArea.Height + prog.workArea.Width, (ent) =>
            {
                if (!prog.workArea.ContainsOrTouches(ent.ServerPos.XYZ) || (ally = ent.GetBehavior <EntityBehaviorProgram>()) == null || ally.getEnergy >= refuelpoint)
                {
                    return(true);
                }

                targetEntity = ent;
                return(false);
            });

            return(targetEntity != null);
        }
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (!prog.CheckArea() || prog.workStack == null)
            {
                return(false);
            }
            if (entity.LeftHandItemSlot?.Itemstack != null && entity.LeftHandItemSlot.StackSize >= entity.LeftHandItemSlot.Itemstack.Collectible.MaxStackSize)
            {
                return(false);
            }

            entityUtil.WalkEntities((prog.workArea.Start + prog.workArea.End) / 2, prog.workArea.Length + prog.workArea.Height + prog.workArea.Width, (ent) =>
            {
                if ((ent is EntityItem) && prog.workArea.ContainsOrTouches(ent.ServerPos.XYZ) && prog.workStack.Equals(entity.World, (ent as EntityItem).Itemstack, GlobalConstants.IgnoredStackAttributes))
                {
                    targetPos = ent.ServerPos.XYZ;
                    return(false);
                }

                return(true);
            });

            return(targetPos != null);
        }
Esempio n. 8
0
        public override bool ShouldExecute()
        {
            //Modified
            prog = entity.GetBehavior <EntityBehaviorProgram>();

            if (prog?.dormant != false || !(entity.LeftHandItemSlot.Itemstack?.Collectible is ItemArrow))
            {
                return(false);
            }
            long ellapsedMs = entity.World.ElapsedMilliseconds;

            if (ellapsedMs - lastCheckOrAttackMs < fullClip || cooldownUntilMs > ellapsedMs)
            {
                return(false);
            }

            Vec3d pos = entity.ServerPos.XYZ.Add(0, entity.CollisionBox.Y2 / 2, 0).Ahead((entity.CollisionBox.X2 - entity.CollisionBox.X1) / 2, 0, entity.ServerPos.Yaw);

            targetEntity = entityUtil.GetNearestEntity(pos, maxDist > maxVerDist ? maxDist : maxVerDist, (e) => {
                if (!e.Alive || !e.IsInteractable || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                for (int i = 0; i < seekEntityCodesExact.Length; i++)
                {
                    if (e.Code.Path == seekEntityCodesExact[i])
                    {
                        if (hasDirectContact(e))
                        {
                            return(true);
                        }
                    }
                }


                for (int i = 0; i < seekEntityCodesBeginsWith.Length; i++)
                {
                    if (e.Code.Path.StartsWithFast(seekEntityCodesBeginsWith[i]) && hasDirectContact(e))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            lastCheckOrAttackMs = entity.World.ElapsedMilliseconds;
            nextShotMs          = 0;
            shotsFired          = 0;

            return(targetEntity != null);
        }
Esempio n. 9
0
        public override bool ShouldExecute()
        {
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (failureTime > entity.World.ElapsedMilliseconds || cooldownUntilMs > entity.World.ElapsedMilliseconds || !prog.CheckArea() || prog.workArea.Height > 0)
            {
                return(false);
            }
            if (entity.LeftHandItemSlot.Itemstack?.Block == null || ExcludeBlock(entity.LeftHandItemSlot.Itemstack.Collectible.Code))
            {
                return(false);
            }

            if (currentarea == null || !AreaCompare())
            {
                currentarea = prog.workArea.Clone();
                targetPos   = currentarea.End.AddCopy(-1, 0, -1);
                if (entity.World.BlockAccessor.GetBlock(targetPos.AsBlockPos).BlockId == 0)
                {
                    return(true);
                }
            }

            if (checkFinished())
            {
                prog.RemoveArea();
                targetPos   = null;
                currentarea = null;
                return(false);
            }

            findNextPoint();

            while (entity.World.BlockAccessor.GetBlock(targetPos.AsBlockPos).BlockId != 0 && !checkFinished())
            {
                if (!findNextPoint())
                {
                    prog.RemoveArea();
                    targetPos   = null;
                    currentarea = null;
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 10
0
        public override bool ShouldExecute()
        {
            EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>();

            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (failureTime > entity.World.ElapsedMilliseconds || cooldownUntilMs > entity.World.ElapsedMilliseconds || !prog.CheckArea() || entity.LeftHandItemSlot.Itemstack?.Collectible?.Tool == null)
            {
                return(false);
            }

            targetPoi = porregistry.GetNearestPoi((prog.workArea.End + prog.workArea.Start) / 2, (float)(prog.workArea.Length + prog.workArea.Height + prog.workArea.Width), (poi) =>
            {
                if (poi.Type != "food" || !prog.workArea.ContainsOrTouches(poi.Position))
                {
                    return(false);
                }
                IAnimalFoodSource foodPoi;

                if ((poi is BlockEntityBerryBush || poi is BlockEntityBeehive) && (foodPoi = poi as IAnimalFoodSource)?.IsSuitableFor(entity) == true)
                {
                    return(true);
                }

                if (poi is BlockEntityFarmland)
                {
                    Block harvest = world.BlockAccessor.GetBlock(poi.Position.AsBlockPos);
                    int stage;
                    int.TryParse(harvest.LastCodePart(), out stage);

                    if ((lumber && (harvest?.Code.Path.Contains("log") == true || harvest?.Code.Path.Contains("bamboo-grown") == true) &&
                         (!harvest.Code.Path.Contains("resin") || !harvest.Code.Path.Contains("resinharvested")) && entity.LeftHandItemSlot.Itemstack.Collectible.Tool == EnumTool.Axe) ||
                        FindMatchCode(harvest.Code) || stage == harvest.CropProps?.GrowthStages || harvest?.GetBehavior <BlockBehaviorHarvestable>() != null)
                    {
                        return(true);
                    }
                }

                return(false);
            }) as IAnimalFoodSource;

            return(targetPoi != null);
        }
Esempio n. 11
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (!IsCraftingSurface())
            {
                return(false);
            }

            targetPos = prog.workPoint.ToVec3d();


            return(targetPos != null);
        }
Esempio n. 12
0
        public override bool ShouldExecute()
        {
            if (rand.NextDouble() > 0.33f)
            {
                return(false);
            }

            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog?.dormant != false || prog.workArea != null || prog.owner == null)
            {
                return(false);
            }

            if (targetEntity == null || !targetEntity.Alive)
            {
                targetEntity = entity.World.GetNearestEntity(entity.ServerPos.XYZ, range, 2, (e) => {
                    return((e as EntityPlayer)?.PlayerUID == prog.owner.PlayerUID);
                });
            }

            if (targetEntity != null && (!targetEntity.Alive || targetEntity.ShouldDespawn))
            {
                targetEntity = null;
            }
            if (targetEntity == null)
            {
                return(false);
            }

            double x = targetEntity.ServerPos.X;
            double y = targetEntity.ServerPos.Y;
            double z = targetEntity.ServerPos.Z;

            double dist = entity.ServerPos.SquareDistanceTo(x, y, z);

            return(dist > maxDistance * maxDistance);
        }
Esempio n. 13
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant)
            {
                return(false);
            }
            if (!(entity.LeftHandItemSlot?.Itemstack?.Collectible is ItemHoneyComb) || prog.CheckBarrel() != true)
            {
                return(false);
            }
            Block check = world.BlockAccessor.GetBlock(prog.workBarrel);

            if (check != null && check.Code.Path.Contains("translocatorbarrel"))
            {
                if (!prog.PutInBarrel(new DummySlot(new ItemStack(world.GetItem(new AssetLocation("game:honeyportion")), 1))))
                {
                    failureTime = entity.World.ElapsedMilliseconds + TemporalHackerConfig.Loaded.BotFailureCooldownMs;
                }
                else
                {
                    entity.World.SpawnItemEntity(new ItemStack(world.GetItem(new AssetLocation("beeswax"))), entity.SidedPos.XYZ);
                    entity.LeftHandItemSlot.TakeOut(1);
                    prog.ConsumeEnergy(12);
                }
                return(false);
            }

            targetPos = prog.workBarrel.ToVec3d();


            return(targetPos != null);
        }
Esempio n. 14
0
        public override bool ShouldExecute()
        {
            if (cooldownUntilMs > entity.World.ElapsedMilliseconds || failureTime > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog == null || prog.dormant || !prog.CheckArea() || prog.workStack == null)
            {
                return(false);
            }
            if (entity.LeftHandItemSlot.Itemstack != null)
            {
                return(false);
            }

            entityUtil.WalkEntities((prog.workArea.Start + prog.workArea.End) / 2, prog.workArea.Length + prog.workArea.Height + prog.workArea.Width, (ent) =>
            {
                if (!prog.workArea.ContainsOrTouches(ent.ServerPos.XYZ) || ent.GetBehavior("milkable") == null && ent.GetBehavior("foodmilk") == null)
                {
                    return(true);
                }

                ITreeAttribute mult = ent.WatchedAttributes.GetTreeAttribute("multiply");

                if (ent.World.Calendar.TotalDays - mult.GetDouble("totalDaysLastBirth") <= 21 && ent.World.Calendar.TotalHours - ent.WatchedAttributes.GetFloat("lastMilkedTotalHours") >= ent.World.Calendar.HoursPerDay)
                {
                    targetEntity = ent;
                    return(false);
                }

                return(true);
            });

            return(targetEntity != null);
        }
Esempio n. 15
0
        public override bool ContinueExecute(float dt)
        {
            if (entity.LeftHandItemSlot.Itemstack?.Collectible.Tool == null)
            {
                return(false);
            }
            Vec3d pos = targetPoi.Position;

            pathTraverser.CurrentTarget.X = pos.X;
            pathTraverser.CurrentTarget.Y = pos.Y;
            pathTraverser.CurrentTarget.Z = pos.Z;

            Cuboidd targetBox = entity.CollisionBox.ToDouble().Translate(entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z);
            double  distance  = targetBox.ShortestDistanceFrom(pos);

            float minDist = 1.5f;

            if (distance <= minDist)
            {
                //if (targetPoi.IsSuitableFor(entity) != true) return false;

                if (harvestAnimMeta != null && !animStart)
                {
                    entity.AnimManager.StartAnimation(harvestAnimMeta);
                    animStart = true;
                }

                harvestTimeNow += dt;

                if (harvestTimeNow >= harvestTime)
                {
                    EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>();

                    if (targetPoi is BlockEntityFarmland)
                    {
                        Block harvest = world.BlockAccessor.GetBlock(targetPoi.Position.AsBlockPos);
                        BlockBehaviorHarvestable bh;

                        if ((bh = harvest?.GetBehavior <BlockBehaviorHarvestable>()) != null && bh.harvestedStack != null)
                        {
                            ItemStack dropStack = bh.harvestedStack.GetNextItemStack();
                            world.PlaySoundAt(bh.harvestingSound, entity.SidedPos.X, entity.SidedPos.Y, entity.SidedPos.Z);
                            world.SpawnItemEntity(dropStack, targetPoi.Position);
                            JsonObject jasset = new JsonObject(JToken.Parse(bh.propertiesAtString));
                            world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(new AssetLocation(jasset["harvestedBlockCode"].AsString())).BlockId, targetPoi.Position.AsBlockPos);
                            prog?.ConsumeEnergy(3);
                            entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 1);
                            return(false);
                        }
                        if ((harvest.Code.Path.Contains("log") || harvest.Code.Path.Contains("bamboo-grown")) && (!harvest.Code.Path.Contains("resin") || !harvest.Code.Path.Contains("resinharvested")) && entity.LeftHandItemSlot.Itemstack.Collectible.Tool == EnumTool.Axe)
                        {
                            string           treetype;
                            Stack <BlockPos> tree = FindTree(world, targetPoi.Position.AsBlockPos, out treetype);
                            prog?.ConsumeEnergy(tree.Count);
                            entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, tree.Count);

                            while (tree.Count > 0)
                            {
                                world.BlockAccessor.BreakBlock(tree.Pop(), null);
                            }

                            return(false);
                        }
                        if (harvest is BlockReeds)
                        {
                            AssetLocation reed = world.BlockAccessor.GetBlock(targetPoi.Position.AsBlockPos).CodeWithPart("harvested", 3);
                            world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(reed).Id, targetPoi.Position.AsBlockPos);
                            world.SpawnItemEntity(new ItemStack(world.GetItem(new AssetLocation("game:cattailtops")), 1), entity.ServerPos.XYZ);
                            prog?.ConsumeEnergy(4);
                            entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 1);
                            return(false);
                        }
                        if (harvest.Code.Path.Contains("tallgrass"))
                        {
                            world.BlockAccessor.BreakBlock(targetPoi.Position.AsBlockPos, null);
                            world.SpawnItemEntity(new ItemStack(world.GetItem(new AssetLocation("game:drygrass")), 1), entity.ServerPos.XYZ);
                            prog?.ConsumeEnergy(3);
                            entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 1);
                            return(false);
                        }

                        world.BlockAccessor.BreakBlock(targetPoi.Position.AsBlockPos, null);
                        prog?.ConsumeEnergy(3);
                        entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 1);
                        return(false);
                    }

                    if (targetPoi is BlockEntityBeehive && targetPoi.IsSuitableFor(entity))
                    {
                        AssetLocation hive = world.BlockAccessor.GetBlock(targetPoi.Position.AsBlockPos).CodeWithPart("empty", 1);
                        world.BlockAccessor.SetBlock(world.BlockAccessor.GetBlock(hive).Id, targetPoi.Position.AsBlockPos);

                        world.SpawnItemEntity(new ItemStack(world.GetItem(new AssetLocation("game:honeycomb")), 3), entity.ServerPos.XYZ);
                        prog?.ConsumeEnergy(8);
                        entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 2);
                        return(false);
                    }

                    if (targetPoi.IsSuitableFor(entity))
                    {
                        targetPoi.ConsumeOnePortion();
                    }
                    prog?.ConsumeEnergy(3);
                    entity.LeftHandItemSlot.Itemstack?.Collectible.DamageItem(world, entity, entity.LeftHandItemSlot, 1);
                    return(false);
                }
            }
            else
            {
                if (!pathTraverser.Active)
                {
                    float rndx = (float)entity.World.Rand.NextDouble() * 0.3f - 0.15f;
                    float rndz = (float)entity.World.Rand.NextDouble() * 0.3f - 0.15f;
                    if (!pathTraverser.NavigateTo(targetPoi.Position.AddCopy(rndx, 0, rndz), moveSpeed, MinDistanceToTarget() - 0.15f, OnGoalReached, OnStuck, false, 500))
                    {
                        return(false);
                    }
                }
            }

            if (nowStuck)
            {
                return(false);
            }

            return(true);
        }
        public override bool ShouldExecute()
        {
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog?.dormant != false)
            {
                return(false);
            }
            long ellapsedMs = entity.World.ElapsedMilliseconds;

            if (ellapsedMs - lastCheckOrAttackMs < attackDurationMs || cooldownUntilMs > ellapsedMs)
            {
                return(false);
            }
            if (whenInEmotionState != null && !entity.HasEmotionState(whenInEmotionState))
            {
                return(false);
            }
            if (whenNotInEmotionState != null && entity.HasEmotionState(whenNotInEmotionState))
            {
                return(false);
            }

            Vec3d pos = entity.ServerPos.XYZ.Add(0, entity.CollisionBox.Y2 / 2, 0).Ahead(entity.CollisionBox.XSize / 2, 0, entity.ServerPos.Yaw);

            int   generation          = entity.WatchedAttributes.GetInt("generation", 0);
            float fearReductionFactor = Math.Max(0f, (10f - generation) / 10f);

            if (whenInEmotionState != null)
            {
                fearReductionFactor = 1;
            }

            if (fearReductionFactor <= 0)
            {
                return(false);
            }

            targetEntity = entity.World.GetNearestEntity(pos, 3f * fearReductionFactor, 3f * fearReductionFactor, (e) => {
                if (!e.Alive || !e.IsInteractable || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                for (int i = 0; i < seekEntityCodesExact.Length; i++)
                {
                    if (e.Code.Path == seekEntityCodesExact[i])
                    {
                        if (e.Code.Path == "player")
                        {
                            IPlayer player = entity.World.PlayerByUid(((EntityPlayer)e).PlayerUID);
                            bool okplayer  =
                                player == null ||
                                (player.WorldData.CurrentGameMode != EnumGameMode.Creative && player.WorldData.CurrentGameMode != EnumGameMode.Spectator && (player as IServerPlayer).ConnectionState == EnumClientState.Playing);

                            return(okplayer && hasDirectContact(e));
                        }

                        if (hasDirectContact(e))
                        {
                            return(true);
                        }
                    }
                }


                for (int i = 0; i < seekEntityCodesBeginsWith.Length; i++)
                {
                    if (e.Code.Path.StartsWithFast(seekEntityCodesBeginsWith[i]) && hasDirectContact(e))
                    {
                        return(true);
                    }
                }

                return(false);
            });

            lastCheckOrAttackMs = entity.World.ElapsedMilliseconds;
            damageInflicted     = false;

            return(targetEntity != null);
        }
Esempio n. 17
0
 public ItemSlotWork(EntityBehaviorProgram beh, InventoryGeneric inventory) : base(inventory)
 {
     this.beh = beh;
 }
Esempio n. 18
0
        public override bool ShouldExecute()
        {
            // React immediately on hurt, otherwise only 1/10 chance of execution
            prog = entity.GetBehavior <EntityBehaviorProgram>();
            if (prog?.dormant != false)
            {
                return(false);
            }
            if (rand.NextDouble() > 0.1f && (whenInEmotionState == null || !entity.HasEmotionState(whenInEmotionState)))
            {
                return(false);
            }

            if (whenInEmotionState != null && !entity.HasEmotionState(whenInEmotionState))
            {
                return(false);
            }
            if (whenNotInEmotionState != null && entity.HasEmotionState(whenNotInEmotionState))
            {
                return(false);
            }
            if (lastSearchTotalMs + 4000 > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }
            if (whenInEmotionState == null && rand.NextDouble() > 0.5f)
            {
                return(false);
            }


            if (jumpAnimOn && entity.World.ElapsedMilliseconds - finishedMs > 2000)
            {
                entity.AnimManager.StopAnimation("jump");
            }

            if (cooldownUntilMs > entity.World.ElapsedMilliseconds)
            {
                return(false);
            }

            if (belowTempThreshold > -99)
            {
                ClimateCondition conds = entity.World.BlockAccessor.GetClimateAt(entity.Pos.AsBlockPos, EnumGetClimateMode.NowValues);
                lowTempMode = conds != null && conds.Temperature <= belowTempThreshold;
            }

            float range = lowTempMode ? belowTempSeekingRange : seekingRange;


            lastSearchTotalMs = entity.World.ElapsedMilliseconds;

            Vec3d ownPos = entity.ServerPos.XYZ;

            targetEntity = (EntityAgent)partitionUtil.GetNearestEntity(entity.ServerPos.XYZ, range, (e) => {
                if (!e.Alive || !e.IsInteractable || e.EntityId == this.entity.EntityId)
                {
                    return(false);
                }

                for (int i = 0; i < seekEntityCodesExact.Length; i++)
                {
                    if (e.Code.Path == seekEntityCodesExact[i])
                    {
                        if (e.Code.Path == "player")
                        {
                            float rangeMul = e.Stats.GetBlended("animalSeekingRange");

                            IPlayer player = entity.World.PlayerByUid(((EntityPlayer)e).PlayerUID);
                            return
                            ((rangeMul == 1 || e.ServerPos.DistanceTo(ownPos) < range * rangeMul) &&
                             (player == null || (player.WorldData.CurrentGameMode != EnumGameMode.Creative && player.WorldData.CurrentGameMode != EnumGameMode.Spectator && (player as IServerPlayer).ConnectionState == EnumClientState.Playing))
                            );
                        }
                        return(true);
                    }
                }


                for (int i = 0; i < seekEntityCodesBeginsWith.Length; i++)
                {
                    if (e.Code.Path.StartsWithFast(seekEntityCodesBeginsWith[i]))
                    {
                        return(true);
                    }
                }

                return(false);
            });



            if (targetEntity != null)
            {
                if (alarmHerd && entity.HerdId > 0)
                {
                    entity.World.GetNearestEntity(entity.ServerPos.XYZ, range, range, (e) =>
                    {
                        EntityAgent agent = e as EntityAgent;
                        if (e.EntityId != entity.EntityId && agent != null && agent.Alive && agent.HerdId == entity.HerdId)
                        {
                            agent.Notify("seekEntity", targetEntity);
                        }

                        return(false);
                    });
                }

                targetPos = targetEntity.ServerPos.XYZ;

                if (entity.ServerPos.SquareDistanceTo(targetPos) <= MinDistanceToTarget())
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Esempio n. 19
0
        public override bool ContinueExecute(float dt)
        {
            if (entity.LeftHandItemSlot.Empty)
            {
                return(false);
            }

            Vec3d pos = targetPoi.Position;

            pathTraverser.CurrentTarget.X = pos.X;
            pathTraverser.CurrentTarget.Y = pos.Y;
            pathTraverser.CurrentTarget.Z = pos.Z;

            Cuboidd targetBox = entity.CollisionBox.ToDouble().Translate(entity.ServerPos.X, entity.ServerPos.Y, entity.ServerPos.Z);
            double  distance  = targetBox.ShortestDistanceFrom(pos);

            float minDist = MinDistanceToTarget();

            if (distance <= minDist)
            {
                if (plantAnimMeta != null && !animStart)
                {
                    entity.AnimManager.StartAnimation(plantAnimMeta);
                    animStart = true;
                }

                plantTimeNow += dt;

                if (plantTimeNow >= plantTime)
                {
                    EntityBehaviorProgram prog = entity.GetBehavior <EntityBehaviorProgram>();
                    if (world.BlockAccessor.GetBlock(targetPoi.Position.AsBlockPos).BlockId != 0)
                    {
                        return(false);
                    }
                    if (entity.LeftHandItemSlot.Itemstack.Collectible is ItemPlantableSeed)
                    {
                        Block cropBlock = world.GetBlock(new AssetLocation("game:crop-" + entity.LeftHandItemSlot.Itemstack.Collectible.LastCodePart() + "-1"));
                        if ((targetPoi as BlockEntityFarmland).TryPlant(cropBlock))
                        {
                            entity.LeftHandItemSlot.TakeOut(1);
                            prog?.ConsumeEnergy(4);
                        }
                    }
                    else if (entity.LeftHandItemSlot.Itemstack.Collectible.WildCardMatch(modSeed))
                    {
                        Block cropBlock = world.GetBlock(new AssetLocation("wildfarming:wildplant-" + entity.LeftHandItemSlot.Itemstack.Collectible.CodeEndWithoutParts(1)));
                        world.BlockAccessor.SetBlock(cropBlock.Id, targetPoi.Position.AsBlockPos);
                        entity.LeftHandItemSlot.TakeOut(1);
                        prog?.ConsumeEnergy(4);
                    }
                    else if (entity.LeftHandItemSlot.Itemstack.Block != null)
                    {
                        world.BlockAccessor.SetBlock(entity.LeftHandItemSlot.Itemstack.Block.Id, targetPoi.Position.AsBlockPos);
                        entity.LeftHandItemSlot.TakeOut(1);
                        prog?.ConsumeEnergy(4);
                    }

                    return(false);
                }
            }
            else
            {
                if (!pathTraverser.Active)
                {
                    float rndx = (float)entity.World.Rand.NextDouble() * 0.3f - 0.15f;
                    float rndz = (float)entity.World.Rand.NextDouble() * 0.3f - 0.15f;
                    if (!pathTraverser.NavigateTo(targetPoi.Position.AddCopy(rndx, 0, rndz), moveSpeed, MinDistanceToTarget() - 0.15f, OnGoalReached, OnStuck, false, 500))
                    {
                        return(false);
                    }
                }
            }

            if (nowStuck)
            {
                return(false);
            }

            return(true);
        }