Beispiel #1
0
        private void displayEntity(Entity entity)
        {
            EntityAlive  entityAlive  = null;
            EntityPlayer entityPlayer = null;
            EntityNPC    entityNPC    = null;
            EntityZombie entityZombie = null;

            if (entity is EntityAlive)
            {
                entityAlive = (EntityAlive)entity;
            }
            if (entity is EntityPlayer)
            {
                entityPlayer = (EntityPlayer)entity;
            }
            if (entity is EntityNPC)
            {
                entityNPC = (EntityNPC)entity;
            }
            if (entity is EntityZombie)
            {
                entityZombie = (EntityZombie)entity;
            }

            string entitydata = " [";

            entitydata += string.Empty;
            entitydata += "id=";
            entitydata += entity.entityId;
            entitydata += ", ";
            entitydata += entity.ToString();
            entitydata += ", Pos=";
            entitydata += entity.GetPosition();
            entitydata += ", Rot=";
            entitydata += entity.rotation;
            entitydata += ", Lifetime=";
            entitydata += ((entity.lifetime != 3.40282347E+38f) ? entity.lifetime.ToString("0.0") : "Max");
            entitydata += ", Remote=";
            entitydata += entity.isEntityRemote;
            entitydata += ", Dead=";
            entitydata += entity.IsDead();
            if (entityAlive != null)
            {
                entitydata += ", CreationTimeSinceLevelLoad=" + entityAlive.CreationTimeSinceLevelLoad;
                entitydata += ", MaxHealth=" + entityAlive.GetMaxHealth();
                entitydata += ", Health=" + entityAlive.Health;
            }
            if (entityZombie != null)
            {
                entitydata += ", IsScoutZombie=" + entityZombie.IsScoutZombie;
            }
            entitydata += "]";
            SendOutput(entitydata);
        }
Beispiel #2
0
    static bool Prefix()
    {
        ulong worldtime = GameManager.Instance.World.GetWorldTime();
        float dawntime  = SkyManager.GetDawnTime();

        if (GameUtils.WorldTimeToHours(worldtime) == dawntime && GameUtils.WorldTimeToMinutes(worldtime) < 1)
        {
            for (int i = 0; i < GameManager.Instance.World.Entities.list.Count; i++)
            {
                EntityAlive entityalive = GameManager.Instance.World.Entities.list[i] as EntityAlive;
                Entity      entity      = GameManager.Instance.World.Entities.list[i] as Entity;
                if (entity.GetSpawnerSource() == EnumSpawnerSource.Biome && entityalive.GetMaxHealth() == entityalive.Health && (entityalive is EntityZombie || entityalive is EntityEnemyAnimal))
                {
                    entityalive.IsDespawned = true;
                    entityalive.MarkToUnload();
                }
            }
            Debug.Log("Cleaned up entities");
        }
        return(true);
    }
Beispiel #3
0
 private void GetMaxHealth(EntityAlive entityAlive) => Bin.Add("MaxHealth", MaxHealth = entityAlive.GetMaxHealth());
Beispiel #4
0
    public void FindAndKillSurroundingEntities()
    {
        //if (entityDamage == 0 || entityVehicle.lastControllerVelocityMagnitude < 5f || Time.time - entityHitAgainDelay < lastEntityHitTime)
        if (entityDamage == 0 || lastControllerVelocityMagnitude < entityHitMinSpeed)
        {
            //DebugMsg("NOT damaging entity: entityDamage = " + entityDamage.ToString() + " | lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
            return;
        }
        else
        {
            //DebugMsg("lastControllerVelocityMagnitude = " + entityVehicle.lastControllerVelocityMagnitude.ToString("0.000"));
        }

        // Try-catch for now because of an error with Bandits and survivors
        try
        {
            Vector3    b = new Vector3(0f, entityVehicle.m_characterController.height / 2f, 0f);
            RaycastHit raycastHit;
            //if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, entityVehicle.motion.magnitude, -1) && raycastHit.collider != null)
            if (Physics.CapsuleCast(entityVehicle.position - b, entityVehicle.position + b, destructionRadius, entityVehicle.motion.normalized, out raycastHit, destructionRadius + 1, -1) && raycastHit.collider != null)
            {
                RootTransformRefEntity component = raycastHit.collider.gameObject.GetComponent <RootTransformRefEntity>();
                if (component)
                {
                    EntityAlive entityAlive = component.RootTransform.GetComponent <Entity>() as EntityAlive;
                    //if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && entityAlive.Spawned && !entityAlive.IsDead())
                    if (entityAlive != null && entityAlive != entityVehicle.AttachedEntities && !entityAlive.IsDead() && !(entityAlive.entityId == lastHitEntityId && Time.time - entityHitAgainDelay < lastEntityHitTime))
                    {
                        int damage = entityDamage;
                        entityHitSpeedRatio = CustomVehiclesUtils.GetRatio(Mathf.Clamp(lastControllerVelocityMagnitude, entityHitMinSpeed, 18f), entityHitMinSpeed, 18f) + 1f;
                        entityHitDamage     = Mathf.RoundToInt((float)damage * entityHitSpeedRatio);
                        bool isCritical = lastControllerVelocityMagnitude > entityCriticalHitMinSpeed;
                        // Doing this in order to properly kill entities. Otherwise they die instantly without animation, and animal corpses disappear.
                        if (entityHitDamage > entityAlive.Health)
                        {
                            entityHitDamage = entityAlive.Health;
                            isCritical      = true;
                        }
                        DamageSourceEntity damageSourceEntity;
                        if (isCritical)
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal);
                        }
                        else
                        {
                            damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        }
                        //DamageSourceEntity damageSourceEntity = new DamageSourceEntity(EnumDamageSourceType.Melee, entityVehicle.player.entityId, -raycastHit.normal, raycastHit.transform.name, raycastHit.point, Vector2.zero);
                        lastHitEntityId = entityAlive.entityId;
                        entityAlive.DamageEntity(damageSourceEntity, entityHitDamage, isCritical, isCritical? 3f : 2f);

                        //DebugMsg("Damage Entity: " + entityAlive.entityId + " | lastControllerVelocityMagnitude = " + lastControllerVelocityMagnitude.ToString("0.000") + " (hit speed ratio = " + entityHitSpeedRatio.ToString("0.000")
                        //    + ") | damage = " + entityHitDamage.ToString("0.000") + " (" + entityAlive.Health.ToString() + "/" + entityAlive.GetMaxHealth().ToString() + ") | hit transform name = " + raycastHit.transform.name + " | critical = " + isCritical.ToString());

                        float vehDmg = (((float)entityAlive.GetMaxHealth()) / 3000.0f) * vehicleDamageFactor_entities * entityHitSpeedRatio;
                        DamageVehicle(vehDmg, 2f);
                        lastEntityHitTime = Time.time;
                    }
                }
            }
        }
        catch (System.Exception e)
        {
            Debug.LogError("An error occurred: " + e);
        }
    }