示例#1
0
    public override int DamageEntity(DamageSource _damageSource, int _strength, bool _criticalHit, float _impulseScale)
    {
        if (EntityUtilities.IsAnAlly(entityId, _damageSource.getEntityId()))
        {
            return(0);
        }

        if (EntityUtilities.GetBoolValue(entityId, "Invulnerable"))
        {
            return(0);
        }

        if (this.Buffs.HasBuff("buffInvulnerable"))
        {
            return(0);
        }

        // If we are being attacked, let the state machine know it can fight back
        emodel.avatarController.SetBool("IsBusy", false);

        // Turn off the trader ID while it deals damage to the entity
        ToggleTraderID(false);
        int Damage = base.DamageEntity(_damageSource, _strength, _criticalHit, _impulseScale);

        ToggleTraderID(true);
        return(Damage);
    }
    public override bool CanExecute()
    {
        DisplayLog("CanExecute() Start");
        bool result = false;

        //    if (entityAliveSDX)
        {
            result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Follow);
            DisplayLog("CanExecute() Follow Task? " + result);
            // Since SetPatrol also uses this method, we'll add an extra check.
            if (result == false)
            {
                result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.SetPatrolPoint);
                DisplayLog(" CanExecute() Set Patrol Point? " + result);
            }

            if (!(this.theEntity is EntityAliveFarmingAnimalSDX) && (result == false))
            {
                return(false);
            }
        }

        // If there is an entity in bounds, then let this AI Task roceed. Otherwise, don't do anything with it.
        result = ConfigureTargetEntity();
        if (result)
        {
            DisplayLog("CanExecute() Configure Target Result: " + result);
        }

        DisplayLog("CanExecute() End: " + result);
        return(result);
    }
示例#3
0
    private void BtnConfirmHireInformation_OnPressed(XUiController _sender, OnPressEventArgs _onPressEventArgs)
    {
        EntityPlayer player = base.xui.playerUI.entityPlayer;

        int entityID = 0;

        if (player.Buffs.HasCustomVar("CurrentNPC"))
        {
            entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
        }

        if (entityID == 0)
        {
            return;
        }

        EntityAliveSDX myEntity = player.world.GetEntity(entityID) as EntityAliveSDX;

        if (myEntity != null)
        {
            EntityUtilities.Hire(entityID, player as EntityPlayerLocal);
        }

        base.xui.playerUI.windowManager.Close(windowGroup.ID);
    }
    public override bool CanExecute()
    {
        bool result = base.CanExecute();

        if (result && this.entityTarget != null)
        {
            if (EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Stay))
            {
                return(false);
            }

            this.theEntity.SetLookPosition(this.entityTarget.getHeadPosition());
            this.theEntity.RotateTo(this.entityTarget, 30f, 30f);

            DisplayLog(" Has Task: " + EntityUtilities.HasTask(this.theEntity.entityId, "Ranged"));

            // Don't execute the approach and attack if there's a ranged ai task, and they are still 4 blocks away
            if (EntityUtilities.HasTask(this.theEntity.entityId, "Ranged"))
            {
                if (result)
                {
                    result = !EntityUtilities.CheckAIRange(theEntity.entityId, entityTarget.entityId);
                }
            }
        }
        return(result);
    }
    public override bool CanExecute()
    {
        bool result = base.CanExecute();

        if (result && this.entityTarget != null)
        {
            this.theEntity.SetLookPosition(this.entityTarget.getHeadPosition());
            this.theEntity.RotateTo(this.entityTarget, 30f, 30f);

            DisplayLog(" Has Task: " + EntityUtilities.HasTask(this.theEntity.entityId, "Ranged"));
            DisplayLog(" Is In Range: " + InRange());
            // Don't execute the approach and attack if there's a ranged ai task, and they are still 4 blocks away
            if (EntityUtilities.HasTask(this.theEntity.entityId, "Ranged") && !InRange())
            {
                DisplayLog(" Has Ranged Attack. Not Moving forward.");
                // If the entity is dead, don't hover over it.
                // this.theEntity.inventory.SetHoldingItemIdx(0);
                return(false);
            }

            EntityUtilities.ChangeHandholdItem(this.theEntity.entityId, EntityUtilities.Need.Melee);
        }


        return(result);
    }
示例#6
0
    public override void OnOpen()
    {
        EntityPlayer player = base.xui.playerUI.entityPlayer;

        int entityID = 0;

        if (player.Buffs.HasCustomVar("CurrentNPC"))
        {
            entityID = (int)player.Buffs.GetCustomVar("CurrentNPC");
        }

        if (entityID == 0)
        {
            return;
        }

        EntityAliveSDX myEntity = player.world.GetEntity(entityID) as EntityAliveSDX;

        if (myEntity != null)
        {
            hireInformationLabel.Text = "Hire " + myEntity.EntityName + " for " + EntityUtilities.GetHireCost(entityID) + " " + EntityUtilities.GetHireCurrency(entityID).ItemClass.GetLocalizedItemName() + "?";
        }

        base.OnOpen();
    }
    public void CheckForSpawn(WorldBase _world, int _clrIdx, Vector3i _blockPos, BlockValue _blockValue)
    {
        if (string.IsNullOrEmpty(SpawnGroup))
        {
            Debug.Log("Spawner does not have a SpawnGroup property set: " + this.GetBlockName());
            return;
        }

        if (_blockValue.meta2 == 0)
        {
            int    ClassID   = 0;
            int    EntityID  = EntityGroups.GetRandomFromGroup(this.SpawnGroup, ref ClassID);
            Entity NewEntity = EntityFactory.CreateEntity(EntityID, _blockPos.ToVector3() + Vector3.up) as Entity;
            if (NewEntity)
            {
                NewEntity.SetSpawnerSource(EnumSpawnerSource.Dynamic);
                GameManager.Instance.World.SpawnEntityInWorld(NewEntity);
                if (Task == "Stay")
                {
                    EntityUtilities.SetCurrentOrder(NewEntity.entityId, EntityUtilities.Orders.Stay);
                }
                if (Task == "Patrol")
                {
                    EntityUtilities.SetCurrentOrder(NewEntity.entityId, EntityUtilities.Orders.Patrol);
                }
                if (Task == "Wander")
                {
                    EntityUtilities.SetCurrentOrder(NewEntity.entityId, EntityUtilities.Orders.Wander);
                }

                _blockValue.meta2 = (byte)1;
                _world.SetBlockRPC(_clrIdx, _blockPos, _blockValue);
            }
        }
    }
示例#8
0
    public override void SetRevengeTarget(EntityAlive _other)
    {
        if (_other)
        {
            // Forgive friendly fire, even from explosions.
            EntityAlive myLeader = EntityUtilities.GetLeaderOrOwner(entityId) as EntityAlive;
            if (myLeader)
            {
                if (myLeader.entityId == _other.entityId)
                {
                    return;
                }
            }
            if (EntityUtilities.IsAnAlly(entityId, _other.entityId))
            {
                return;
            }

            if (_other.IsDead())
            {
                return;
            }
        }

        if (_other == null)
        {
            // Reset the hand held back to their preferred item 0
            EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Ranged, 0);
        }

        base.SetRevengeTarget(_other);
        //  Debug.Log("Adding Buff for RevengeTarget() ");
        Buffs.AddBuff("buffNotifyTeamAttack", -1, true);
    }
示例#9
0
    public override void SetAttackTarget(EntityAlive _attackTarget, int _attackTargetTime)
    {
        if (_attackTarget != null)
        {
            if (_attackTarget.IsDead())
            {
                return;
            }
        }


        if (_attackTarget == null)
        {
            // Some of the AI tasks resets the attack target when it falls down stunned; this will prevent the NPC from ignoring its stunned opponent.
            if (attackTarget != null && attackTarget.IsAlive())
            {
                return;
            }

            // Reset the hand held back to their preferred item 0
            EntityUtilities.ChangeHandholdItem(this.entityId, EntityUtilities.Need.Ranged, 0);
        }

        base.SetAttackTarget(_attackTarget, _attackTargetTime);
        // Debug.Log("Adding Buff for Attack Target() ");
        Buffs.AddBuff("buffNotifyTeamAttack", -1, true);
    }
示例#10
0
    public override bool CanExecute()
    {
        //  return false;
        DisplayLog("CanExecute()");
        bool result = false;

        if (entityAliveSDX)
        {
            result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Loot);
            DisplayLog("CanExecute() Loot Task? " + result);
            if (result == false)
            {
                return(false);
            }
        }

        if (FindBoundsOfPrefab())
        {
            DisplayLog(" Within the Bounds of a Prefab");
            ScanForTileEntityInList();
            DisplayLog(" Searching for closes container: " + this.lstTileContainers.Count);
            result = FindNearestContainer();
        }

        DisplayLog("CanExecute() End: " + result);
        return(result);
    }
    public override bool Continue()
    {
        bool result = base.Continue();

        // Non zombies should continue to attack
        if (this.entityTarget.IsDead())
        {
            this.theEntity.IsEating = false;
            this.theEntity.SetAttackTarget(null, 0);
            this.theEntity.SetRevengeTarget(null);
            return(false);
        }


        if (result)
        {
            // Don't execute the approach and attack if there's a ranged ai task, and they are still 4 blocks away
            if (EntityUtilities.HasTask(this.theEntity.entityId, "Ranged"))
            {
                result = !EntityUtilities.CheckAIRange(theEntity.entityId, entityTarget.entityId);
            }
        }

        if (!result)
        {
            return(result);
        }

        EntityUtilities.ChangeHandholdItem(this.theEntity.entityId, EntityUtilities.Need.Melee);


        return(result);
    }
    // Over-ride for CopyProperties to allow it to read in StartingQuests.
    public override void CopyPropertiesFromEntityClass()
    {
        base.CopyPropertiesFromEntityClass();
        EntityClass entityClass = EntityClass.list[this.entityClass];

        flEyeHeight = EntityUtilities.GetFloatValue(entityId, "EyeHeight");

        // Read in a list of names then pick one at random.
        if (entityClass.Properties.Values.ContainsKey("Names"))
        {
            string   text  = entityClass.Properties.Values["Names"];
            string[] Names = text.Split(',');

            int index = UnityEngine.Random.Range(0, Names.Length);
            strMyName = Names[index];
        }

        if (entityClass.Properties.Values.ContainsKey("SleeperInstantAwake"))
        {
            isAlwaysAwake = true;
        }
        if (entityClass.Properties.Values.ContainsKey("Titles"))
        {
            string   text  = entityClass.Properties.Values["Titles"];
            string[] Names = text.Split(',');
            int      index = UnityEngine.Random.Range(0, Names.Length);
            strTitle = Names[index];
        }


        if (entityClass.Properties.Classes.ContainsKey("Boundary"))
        {
            DisplayLog(" Found Bandary Settings");
            String            strBoundaryBox     = "0,0,0";
            String            strCenter          = "0,0,0";
            DynamicProperties dynamicProperties3 = entityClass.Properties.Classes["Boundary"];
            foreach (KeyValuePair <string, object> keyValuePair in dynamicProperties3.Values.Dict.Dict)
            {
                DisplayLog("Key: " + keyValuePair.Key);
                if (keyValuePair.Key == "BoundaryBox")
                {
                    DisplayLog(" Found a Boundary Box");
                    strBoundaryBox = dynamicProperties3.Values[keyValuePair.Key];
                    continue;
                }

                if (keyValuePair.Key == "Center")
                {
                    DisplayLog(" Found a Center");
                    strCenter = dynamicProperties3.Values[keyValuePair.Key];
                    continue;
                }
            }

            Vector3 Box    = StringParsers.ParseVector3(strBoundaryBox, 0, -1);
            Vector3 Center = StringParsers.ParseVector3(strCenter, 0, -1);
            ConfigureBounaryBox(Box, Center);
        }
    }
示例#13
0
    public static Vector3 GetNewPositon(int EntityID, bool Random = false)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return(Vector3.zero);
        }


        Vector3        result = Vector3.zero;
        List <Vector3> Paths  = SphereCache.GetPaths(EntityID);

        if (Paths == null || Paths.Count == 0)
        {
            //  Grab a list of blocks that are configured for this class.
            //    <property name="PathingBlocks" value="PathingCube" />
            List <string> Blocks = EntityUtilities.ConfigureEntityClass(EntityID, "PathingBlocks");
            if (Blocks.Count == 0)
            {
                Blocks.Add("PathingCube");
            }

            //Scan for the blocks in the area
            List <Vector3> PathingVectors = ModGeneralUtilities.ScanForTileEntityInChunksListHelper(myEntity.position, Blocks, EntityID);
            if (PathingVectors == null || PathingVectors.Count == 0)
            {
                return(result);
            }

            //Add to the cache
            SphereCache.AddPaths(EntityID, PathingVectors);
        }

        // Finds the closet block we matched with.
        Vector3 tMin = new Vector3();

        if (Random)
        {
            tMin = SphereCache.GetRandomPath(EntityID);
        }
        else
        {
            tMin = ModGeneralUtilities.FindNearestBlock(myEntity.position, SphereCache.GetPaths(EntityID));
            if (tMin == Vector3.zero)
            {
                return(tMin);
            }
        }
        // Remove it from the cache.
        SphereCache.RemovePath(EntityID, tMin);

        result = GameManager.Instance.World.FindSupportingBlockPos(tMin);
        // Center the pathing position.
        result.x = (float)Utils.Fastfloor(result.x) + 0.5f;
        result.y = (float)Utils.Fastfloor(result.y) + 0.5f;
        result.z = (float)Utils.Fastfloor(result.z) + 0.5f;
        return(result);
    }
    public override bool Continue()
    {
        DisplayLog("Continue() Start");

        bool result = false;

        //   if (entityAliveSDX)
        {
            result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Follow);
            if (result == false)
            {
                // Since SetPatrol also uses this method, we'll add an extra check.
                result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.SetPatrolPoint);
            }

            if (result == false)
            {
                return(false);
            }
        }

        if (this.theEntity.getMoveHelper().BlockedTime > 2)
        {
            DisplayLog(" Blocked Time: " + this.theEntity.getMoveHelper().BlockedTime);

            DisplayLog("Entity is blocked. Resetting its move position");
            // If the npc seems lost, set a generate move to match the leader's position
            this.theEntity.getMoveHelper().SetMoveTo(this.entityTargetPos, false);

            return(false);
        }
        if (pathCounter == 0) // briefly pause if you are at the end of the path to let other tasks run
        {
            result = false;
        }

        result = ConfigureTargetEntity();


        if (this.entityTarget == null)
        {
            if (this.theEntity.Buffs.HasCustomVar("Leader"))
            {
                DisplayLog(" Checking my Leader");
                // Find out who the leader is.
                int   PlayerID = (int)this.theEntity.Buffs.GetCustomVar("Leader");
                float distance = this.theEntity.GetDistance(this.theEntity.world.GetEntity(PlayerID));
                DisplayLog(" Distance: " + distance);
                if (distance > this.theEntity.GetSeeDistance())
                {
                    DisplayLog("I am too far away from my leader. Teleporting....");
                    SetCloseSpawnPoint();
                    DisplayLog(" my Position: " + this.theEntity.position + " Target Position: " + this.entityTargetPos + " My Leader position: " + this.entityTarget.position);
                }
            }
        }
        DisplayLog("Continue() End: " + result);
        return(result);
    }
示例#15
0
 public static bool Postfix(bool __result, EAIApproachAndAttackTarget __instance, ref bool ___isTargetToEat)
 {
     if (__result && EntityUtilities.IsHuman(__instance.theEntity.entityId))
     {
         return(SphereII_EAIApproachAndAttackTarget_Helper.CanContinue(__instance));
     }
     return(__result);
 }
示例#16
0
    public static Vector3 GetNewPositon(int EntityID, int maxBlocks = 30)
    {
        EntityAlive myEntity = GameManager.Instance.World.GetEntity(EntityID) as EntityAlive;

        if (myEntity == null)
        {
            return(Vector3.zero);
        }

        if (!EntityUtilities.CheckProperty(EntityID, "PathingBlocks"))
        {
            return(Vector3.zero);
        }

        Vector3        result = Vector3.zero;
        List <Vector3> Paths  = SphereCache.GetPaths(EntityID);

        if (Paths == null || Paths.Count == 0)
        {
            //  Grab a list of blocks that are configured for this class.
            //    <property name="PathingBlocks" value="PathingCube" />
            List <string> Blocks = EntityUtilities.ConfigureEntityClass(EntityID, "PathingBlocks");
            if (Blocks.Count == 0)
            {
                // DisplayLog("No Blocks configured. Setting Default", __instance.theEntity);
                // Blocks.Add("PathingCube");
                return(result);
            }

            //Scan for the blocks in the area
            List <Vector3> PathingVectors = ModGeneralUtilities.ScanForBlockInListHelper(myEntity.position, Blocks, maxBlocks);
            if (PathingVectors.Count == 0)
            {
                return(result);
            }

            //Add to the cache
            SphereCache.AddPaths(EntityID, PathingVectors);
        }

        Vector3 newposition = SphereCache.GetRandomPath(EntityID);

        if (newposition == Vector3.zero)
        {
            return(result);
        }

        // Remove it from the cache.
        SphereCache.RemovePath(EntityID, newposition);

        result = GameManager.Instance.World.FindSupportingBlockPos(newposition);
        //Debug.Log("Position: " + result);
        // Center the pathing position.
        result.x = (float)Utils.Fastfloor(result.x) + 0.5f;
        result.y = (float)Utils.Fastfloor(result.y) + 0.5f;
        result.z = (float)Utils.Fastfloor(result.z) + 0.5f;
        return(result);
    }
        public static bool Prefix(EntityAlive ___entity)
        {
            if (EntityUtilities.IsHuman(___entity.entityId))
            {
                return(false);
            }

            return(true);
        }
 public void ShouldHaveDefaultConstructor()
 {
     foreach (var entity in EntityUtilities.GetEntities())
     {
         var constructors       = entity.GetConstructors();
         var defaultConstructor = constructors.FirstOrDefault(x => x.IsPublic && x.GetParameters().Length == 0);
         Assert.IsNotNull(defaultConstructor, $"Entity {entity.Name} should public contain default constructor");
     }
 }
        public static bool Prefix(EntityMoveHelper __instance)
        {
            if (EntityUtilities.IsHuman(__instance.entity.entityId))
            {
                return(false);
            }

            return(true);
        }
示例#20
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        EntityAlive leader = EntityUtilities.GetLeaderOrOwner(this.theEntity.entityId) as EntityAlive;

        if (!leader)
        {
            return(false);
        }

        // Search in the bounds are to try to find the most appealing entity to follow.
        Bounds bb = new Bounds(this.theEntity.position, new Vector3(this.theEntity.GetSeeDistance(), 20f, this.theEntity.GetSeeDistance()));

        //Bounds bb = new Bounds(this.theEntity.position, new Vector3(20f, 20f,20f));
        this.theEntity.world.GetEntitiesInBounds(typeof(EntityAlive), bb, this.NearbyEntities);
        DisplayLog(" Nearby Entities: " + this.NearbyEntities.Count);
        for (int i = this.NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAlive x = (EntityAlive)this.NearbyEntities[i];
            if (x != this.theEntity)
            {
                if (x.IsDead())
                {
                    continue;
                }

                DisplayLog("Nearby Entity: " + x.EntityName);
                if (x.GetAttackTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);
                    return(true);
                }

                if (x.GetRevengeTarget() == leader)
                {
                    DisplayLog(" My leader is being avenged by " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }

                if (x.GetDamagedTarget() == leader)
                {
                    DisplayLog(" My leader is being attacked by something that damaged it " + x.ToString());
                    targetEntity = x;
                    this.theEntity.SetRevengeTarget(targetEntity);

                    return(true);
                }
            }
        }

        return(false);
    }
示例#21
0
        public static bool Postfix(bool __result, EAITarget __instance, EntityAlive _e)
        {
            if (!EntityUtilities.IsHuman(__instance.theEntity.entityId))
            {
                return(__result);
            }

            if (__instance.theEntity.IsSleeping)
            {
                return(__result);
            }

            //  Debug.Log("Entity: " + __instance.theEntity.entityId + " Target: " + _e.entityId +  " + Result: " + __result);
            // The base class sees this as a valid target.
            if (__result)
            {
                // same faction
                if (__instance.theEntity.factionId == _e.factionId)
                {
                    return(false);
                }

                // if the attack cool down is applied, don't set a new target for 30 seconds.
                if (__instance.theEntity.Buffs.HasBuff("buffAttackCoolDown"))
                {
                    return(false);
                }

                // We have some complicated checks here, since this method gets called by 3 different target methods.
                FactionManager.Relationship myRelationship = FactionManager.Instance.GetRelationshipTier(__instance.theEntity, _e);
                // Debug.Log("Checking Relationship: " + myRelationship.ToString());
                switch (myRelationship)
                {
                case FactionManager.Relationship.Hate:
                    return(true);

                case FactionManager.Relationship.Dislike:
                case FactionManager.Relationship.Neutral:
                    // If you don't like them, or are more or less neutral to them,
                    // know the difference between an aggressive hit, or just a regular scan of entities.
                    if (__instance is EAISetNearestEntityAsTarget)
                    {
                        return(false);    // they aren't an enemy to kill right off
                    }
                    if (__instance is EAISetAsTargetIfHurt)
                    {
                        return(true);     // They suck! They hurt you. Get them!
                    }
                    return(false);

                default:
                    return(false);
                }
            }
            return(__result);
        }
示例#22
0
    public bool CheckSurroundingEntities()
    {
        this.NearbyEntities.Clear();
        NearbyEnemies.Clear();

        EntityAlive leader = EntityUtilities.GetLeaderOrOwner(this.theEntity.entityId) as EntityAlive;


        float originalView = this.theEntity.GetMaxViewAngle();

        this.theEntity.SetMaxViewAngle(360f);

        // Search in the bounds are to try to find the most appealing entity to follow.
        Bounds bb = new Bounds(this.theEntity.position, new Vector3(20f, 20f, 20f));

        this.theEntity.world.GetEntitiesInBounds(typeof(EntityAlive), bb, this.NearbyEntities);
        DisplayLog(" Nearby Entities: " + this.NearbyEntities.Count);
        for (int i = this.NearbyEntities.Count - 1; i >= 0; i--)
        {
            EntityAlive x = (EntityAlive)this.NearbyEntities[i];
            if (x is EntityVehicle)
            {
                continue;
            }

            if (x.IsDead())
            {
                continue;
            }
            if (x != this.theEntity && x.IsAlive())
            {
                if (leader != null && x == leader)
                {
                    continue;
                }

                if (x.CanSee(this.theEntity.position))
                {
                    DisplayLog(" I can be seen by an enemy.");
                    if (!this.theEntity.CanSee(x.position))
                    {
                        DisplayLog(" I know an entity is there, but I can't see it: " + x.EntityName);
                        continue;
                    }
                }
                DisplayLog("Nearby Entity: " + x.EntityName);
                if (CheckFactionForEnemy(x))
                {
                    NearbyEnemies.Add(x);
                }
            }
        }

        this.theEntity.SetMaxViewAngle(originalView);
        return(NearestEnemy());
    }
示例#23
0
    public override bool Attack(bool _bAttackReleased)
    {
        if (attackTarget == null)
        {
            EntityUtilities.ChangeHandholdItem(entityId, EntityUtilities.Need.Ranged, 0);
            return(false);
        }

        return(base.Attack(_bAttackReleased));
    }
示例#24
0
    public override void Start()
    {
        EntityUtilities.ChangeHandholdItem(theEntity.entityId, EntityUtilities.Need.Melee);

        base.Start();
        if (this.entityTarget != null)
        {
            this.theEntity.RotateTo(this.entityTarget, 45f, 45f);
        }
    }
示例#25
0
    public static bool Prefix(EModelBase __instance, Entity ___entity, Transform ___neckParentTransform, Transform ___headTransform, ref Vector3 ___lookAtPos, float ___lookAtMaxAngle,
                              ref Quaternion ___lookAtRot, Transform ___neckTransform, ref float ___lookAtBlendPer, ref float ___lookAtBlendPerTarget, bool ___lookAtIsPos)
    {
        EntityAliveSDX entityAlive = ___entity as EntityAliveSDX;

        if (!entityAlive)
        {
            return(true);
        }

        EnumEntityStunType currentStun = entityAlive.bodyDamage.CurrentStun;
        float deltaTime = Time.deltaTime;

        if (entityAlive.IsDead() || (currentStun != EnumEntityStunType.None && currentStun != EnumEntityStunType.Getup))
        {
            ___lookAtBlendPerTarget = 0f;
        }

        // If the entity has an attack target, look at them, instead of hte player.
        Entity target = EntityUtilities.GetAttackOrReventTarget(___entity.entityId);

        if (target != null)
        {
            ___lookAtBlendPerTarget -= deltaTime;
            if (target && entityAlive.CanSee(target as EntityAlive))
            {
                ___lookAtPos            = target.getHeadPosition();
                ___lookAtBlendPerTarget = 1f;
            }
        }
        if (___lookAtBlendPer <= 0f && ___lookAtBlendPerTarget <= 0f)
        {
            return(true);
        }
        ___lookAtBlendPer = Mathf.MoveTowards(___lookAtBlendPer, ___lookAtBlendPerTarget, deltaTime * 2f);

        Quaternion rotation3 = ___neckParentTransform.rotation;
        Transform  transform = ___headTransform;
        Vector3    upwards   = rotation3 * Vector3.up;
        Quaternion quaternion;

        quaternion  = Quaternion.LookRotation(___lookAtPos - Origin.position - transform.position);
        quaternion *= Quaternion.Slerp(Quaternion.identity, transform.localRotation, 0.5f);

        Quaternion b = Quaternion.RotateTowards(rotation3, quaternion, ___lookAtMaxAngle);

        ___lookAtRot = Quaternion.Slerp(___lookAtRot, b, 0.16f);
        float num = ___lookAtBlendPer;

        ___neckTransform.rotation = Quaternion.Slerp(___neckTransform.rotation, ___lookAtRot, num * 0.4f);
        Quaternion rotation2 = transform.rotation;

        transform.rotation = Quaternion.Slerp(rotation2, ___lookAtRot, num);
        return(false);
    }
        public static bool Prefix(ref EntityMoveHelper __instance, bool calcYaw, float distance = 0f, float heightDiff = 0)
        {
            //Debug.Log("Start Jump");
            if (heightDiff == 1.4f)
            {
                EntityUtilities.Stop(__instance.entity.entityId);
                return(false);
            }

            return(true);
        }
示例#27
0
    public override bool CanExecute()
    {
        DisplayLog("CanExecute() Start");
        bool result = false;

        if (entityAliveSDX)
        {
            result = EntityUtilities.CanExecuteTask(this.theEntity.entityId, EntityUtilities.Orders.Patrol);
            DisplayLog("CanExecute() Follow Task? " + result);
            if (result == false)
            {
                return(false);
            }
        }

        // if The entity is busy, don't continue patrolling.
        bool isBusy = false;

        if (this.theEntity.emodel.avatarController.TryGetBool("IsBusy", out isBusy))
        {
            if (isBusy)
            {
                return(true);
            }
        }

        //if (!FetchOrders())
        //    result = false;

        SetPatrolVectors();

        if (entityAliveSDX.PatrolCoordinates.Count > 0)
        {
            if (PatrolPointsCounter > entityAliveSDX.PatrolCoordinates.Count - 1)
            {
                PatrolPointsCounter = entityAliveSDX.PatrolCoordinates.Count - 1;
            }
        }
        else
        {
            return(false);
        }

        this.theEntity.SetInvestigatePosition(this.lstPatrolPoints[PatrolPointsCounter], 1200);
        if (this.theEntity.HasInvestigatePosition)
        {
            DisplayLog(" I have an intesgation Position. Starting to Patrol");
            this.theEntity.emodel.avatarController.SetTrigger("IsPatrolling");
            result = true;
        }

        DisplayLog("CanExecute() End: " + result);
        return(result);
    }
 public static bool Prefix(ref EntityAlive ___entity, bool calcYaw, float distance = 0f, float heightDiff = 0)
 {
     if (EntityUtilities.IsHuman(___entity.entityId))
     {
         if (heightDiff == 1.4f)
         {
             EntityUtilities.Stop(___entity.entityId);
             return(false);
         }
     }
     return(true);
 }
示例#29
0
 public void EntitiesWithNamePropertyShouldImplementEntityWithNameInterface()
 {
     foreach (var entity in EntityUtilities.GetEntities())
     {
         if (entity.HasProperty("Name", typeof(string)))
         {
             Assert.IsTrue(
                 entity.Implements <IEntityWithName>(),
                 $"Type '{entity.Name}' should implement IEntityWithName interface");
         }
     }
 }
示例#30
0
 public void EntitiesWithStatusPropertyShouldImplementEntityWithStatusInterface()
 {
     foreach (var entity in EntityUtilities.GetEntities())
     {
         if (entity.HasProperty("Status", typeof(bool)))
         {
             Assert.IsTrue(
                 entity.Implements <IEntityWithStatus>(),
                 $"Type '{entity.Name}' should implement IEntityWithStatus interface");
         }
     }
 }