Пример #1
0
 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
 {
     m_subsystemTime   = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true);
     m_subsystemAudio  = base.Project.FindSubsystem <SubsystemAudio>(throwOnError: true);
     m_componentMount  = base.Entity.FindComponent <ComponentMount>(throwOnError: true);
     m_componentBody   = base.Entity.FindComponent <ComponentBody>(throwOnError: true);
     m_componentDamage = base.Entity.FindComponent <ComponentDamage>(throwOnError: true);
 }
Пример #2
0
        public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
        {
            base.Load(valuesDictionary, idToEntityMap);
            m_componentBody  = Entity.FindComponent <ComponentBody>(true);
            componentDamage  = Entity.FindComponent <ComponentDamage>();
            m_componentMount = Entity.FindComponent <ComponentMount>(true);
            if ((ComponentEngine = Entity.FindComponent <ComponentEngine>()) != null)
            {
                m_componentBody.CollidedWithBody += CollidedWithBody;
            }
            else
            {
                ParentBody = valuesDictionary.GetValue("ParentBody", default(EntityReference)).GetComponent <ComponentTrain>(Entity, idToEntityMap, false);
            }

            Direction = valuesDictionary.GetValue("Direction", 0);
        }
Пример #3
0
        public static void AttackBody(ComponentBody target, ComponentCreature attacker, Vector3 hitPoint, Vector3 hitDirection, float attackPower, bool isMeleeAttack)
        {
            if (attacker != null && attacker is ComponentPlayer && target.Entity.FindComponent <ComponentPlayer>() != null && !target.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true).WorldSettings.IsFriendlyFireEnabled)
            {
                attacker.Entity.FindComponent <ComponentGui>(throwOnError: true).DisplaySmallMessage(LanguageControl.Get(fName, 3), Color.White, blinking: true, playNotificationSound: true);
                return;
            }
            if (attackPower > 0f)
            {
                ComponentClothing componentClothing = target.Entity.FindComponent <ComponentClothing>();
                if (componentClothing != null)
                {
                    attackPower = componentClothing.ApplyArmorProtection(attackPower);
                }
                ComponentLevel componentLevel = target.Entity.FindComponent <ComponentLevel>();
                if (componentLevel != null)
                {
                    attackPower /= componentLevel.ResilienceFactor;
                }
                ComponentHealth componentHealth = target.Entity.FindComponent <ComponentHealth>();
                if (componentHealth != null)
                {
                    float  num = attackPower / componentHealth.AttackResilience;
                    string cause;
                    if (attacker != null)
                    {
                        string str          = attacker.KillVerbs[s_random.Int(0, attacker.KillVerbs.Count - 1)];
                        string attackerName = attacker.DisplayName;
                        cause = string.Format(LanguageControl.Get(fName, 4), attackerName, LanguageControl.Get(fName, str));
                    }
                    else
                    {
                        switch (s_random.Int(0, 5))
                        {
                        case 0:
                            cause = LanguageControl.Get(fName, 5);
                            break;

                        case 1:
                            cause = LanguageControl.Get(fName, 6);
                            break;

                        case 2:
                            cause = LanguageControl.Get(fName, 7);
                            break;

                        case 3:
                            cause = LanguageControl.Get(fName, 8);
                            break;

                        case 4:
                            cause = LanguageControl.Get(fName, 9);
                            break;

                        default:
                            cause = LanguageControl.Get(fName, 10);
                            break;
                        }
                    }
                    float health = componentHealth.Health;
                    componentHealth.Injure(num, attacker, ignoreInvulnerability: false, cause);
                    if (num > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound("Audio/Impacts/Body", 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                        float num2 = (health - componentHealth.Health) * componentHealth.AttackResilience;
                        if (attacker is ComponentPlayer && num2 > 0f)
                        {
                            string text2 = (0f - num2).ToString("0", CultureInfo.InvariantCulture);
                            HitValueParticleSystem particleSystem = new HitValueParticleSystem(hitPoint + 0.75f * hitDirection, 1f * hitDirection + attacker.ComponentBody.Velocity, Color.White, text2);
                            target.Project.FindSubsystem <SubsystemParticles>(throwOnError: true).AddParticleSystem(particleSystem);
                        }
                    }
                }
                ComponentDamage componentDamage = target.Entity.FindComponent <ComponentDamage>();
                if (componentDamage != null)
                {
                    float num3 = attackPower / componentDamage.AttackResilience;
                    componentDamage.Damage(num3);
                    if (num3 > 0f)
                    {
                        target.Project.FindSubsystem <SubsystemAudio>(throwOnError: true).PlayRandomSound(componentDamage.DamageSoundName, 1f, s_random.Float(-0.3f, 0.3f), target.Position, 4f, autoDelay: false);
                    }
                }
            }
            float num4 = 0f;
            float x    = 0f;

            if (isMeleeAttack && attacker != null)
            {
                float num5 = (attackPower >= 2f) ? 1.25f : 1f;
                float num6 = MathUtils.Pow(attacker.ComponentBody.Mass / target.Mass, 0.5f);
                float x2   = num5 * num6;
                num4 = 5.5f * MathUtils.Saturate(x2);
                x    = 0.25f * MathUtils.Saturate(x2);
            }
            else if (attackPower > 0f)
            {
                num4 = 2f;
                x    = 0.2f;
            }
            if (num4 > 0f)
            {
                target.ApplyImpulse(num4 * Vector3.Normalize(hitDirection + s_random.Vector3(0.1f) + 0.2f * Vector3.UnitY));
                ComponentLocomotion componentLocomotion = target.Entity.FindComponent <ComponentLocomotion>();
                if (componentLocomotion != null)
                {
                    componentLocomotion.StunTime = MathUtils.Max(componentLocomotion.StunTime, x);
                }
            }
        }
Пример #4
0
        public void Update(float dt)
        {
            if (ComponentEngine != null)
            {
                ComponentEngine.Coordinates = new Point3((int)m_componentBody.Position.X, (int)m_componentBody.Position.Y, (int)m_componentBody.Position.Z);
            }
            if (m_componentMount.Rider != null)
            {
                var player = m_componentMount.Rider.Entity.FindComponent <ComponentPlayer>(true);
                player.ComponentLocomotion.LookOrder = player.ComponentInput.PlayerInput.Look;
            }

            ComponentTrain t     = this;
            int            level = 0;

            for (; t.ParentBody != null; level++)
            {
                t = t.ParentBody;
            }
            if (level > 0)
            {
                var body = t.m_componentBody;
                var pos  = body.Position;
                var r    = body.Rotation;
                Utils.SubsystemTime.QueueGameTimeDelayedExecution(Utils.SubsystemTime.GameTime + 0.23 * level, delegate
                {
                    if (body.Velocity.XZ.LengthSquared() > 10f)
                    {
                        m_componentBody.Position = pos;
                        m_componentBody.Rotation = r;
                    }
                });
                m_outOfMountTime = Vector3.DistanceSquared(ParentBody.m_componentBody.Position, m_componentBody.Position) > 8f
                                        ? m_outOfMountTime + dt
                                        : 0f;
                ComponentDamage ComponentDamage = ParentBody.Entity.FindComponent <ComponentDamage>();
                if (m_outOfMountTime > 1f || (componentDamage != null && componentDamage.Hitpoints <= .05f) || ComponentDamage != null && ComponentDamage.Hitpoints <= .05f)
                {
                    ParentBody = null;
                }
                return;
            }

            switch (Direction)
            {
            case 0:
            case 2:
                m_componentBody.Position = new Vector3(MathUtils.Floor(m_componentBody.Position.X) + 0.5f, m_componentBody.Position.Y, m_componentBody.Position.Z);
                break;

            case 1:
            case 3:
                m_componentBody.Position = new Vector3(m_componentBody.Position.X, m_componentBody.Position.Y, MathUtils.Floor(m_componentBody.Position.Z) + 0.5f);
                break;
            }

            if (ComponentEngine != null && ComponentEngine.HeatLevel >= 100f && m_componentBody.StandingOnValue.HasValue)
            {
                var result = Utils.SubsystemTerrain.Raycast(m_componentBody.Position, m_componentBody.Position + new Vector3(0, -3f, 0), false, true, null);

                if (result.HasValue && Terrain.ExtractContents(result.Value.Value) == RailBlock.Index && (dt *= SimulateRail(RailBlock.GetRailType(Terrain.ExtractData(result.Value.Value)))) > 0f)
                {
                    m_componentBody.m_velocity += dt * rotation.ToForwardVector();
                }
            }
            m_componentBody.Rotation = Quaternion.Slerp(m_componentBody.Rotation, rotation, 0.15f);
        }