Ejemplo n.º 1
0
        public List <Body> GenerateRandomSpawn(int numCreatures, Vector3 position)
        {
            if (Race.CreatureTypes.Count == 0)
            {
                return(new List <Body>());
            }

            List <Body> toReturn = new List <Body>();

            for (int i = 0; i < numCreatures; i++)
            {
                string  creature = Race.CreatureTypes[MathFunctions.Random.Next(Race.CreatureTypes.Count)];
                Vector3 offset   = MathFunctions.RandVector3Cube() * 5;
                Voxel   voxel    = new Voxel();

                if (World.ChunkManager.ChunkData.GetFirstVoxelUnder(position + offset, ref voxel, true))
                {
                    Body       body = EntityFactory.CreateEntity <Body>(creature, position + offset);
                    CreatureAI ai   = body.GetChildrenOfType <CreatureAI>().FirstOrDefault();

                    if (ai != null)
                    {
                        ai.Faction.Minions.Remove(ai);

                        Minions.Add(ai);
                        ai.Faction         = this;
                        ai.Creature.Allies = Name;
                    }

                    toReturn.Add(body);
                }
            }

            return(toReturn);
        }
Ejemplo n.º 2
0
        bool IsDwarf(Body body)
        {
            List <Creature> dwarves = body.GetChildrenOfType <Creature>();

            if (dwarves.Count <= 0)
            {
                return(false);
            }

            Creature dwarf = dwarves[0];

            return(dwarf.Faction == Player.Faction && !Player.SelectedMinions.Contains(dwarf.AI));
        }
Ejemplo n.º 3
0
        public bool Perform(Creature performer, Body other, DwarfTime time, float bonus, Vector3 pos, string faction)
        {
            switch (TriggerMode)
            {
            case AttackTrigger.Timer:
                RechargeTimer.Update(time);
                if (!RechargeTimer.HasTriggered)
                {
                    return(false);
                }
                break;

            case AttackTrigger.Animation:
                if (performer.Sprite.CurrentAnimation == null ||
                    performer.Sprite.CurrentAnimation.CurrentFrame != TriggerFrame)
                {
                    return(false);
                }
                break;
            }
            switch (Mode)
            {
            case AttackMode.Melee:
            {
                Health health = other.GetChildrenOfType <Health>().FirstOrDefault();
                if (health != null)
                {
                    health.Damage(DamageAmount + bonus);
                }

                PlayNoise(other.LocalTransform.Translation);
                if (HitParticles != "")
                {
                    PlayState.ParticleManager.Trigger(HitParticles, other.LocalTransform.Translation, Color.White, 5);
                }

                if (HitAnimation != null)
                {
                    HitAnimation.Reset();
                    HitAnimation.Play();
                    IndicatorManager.DrawIndicator(HitAnimation, other.BoundingBox.Center(), 0.6f, 2.0f, MathFunctions.RandVector2Circle(), Color.White, MathFunctions.Rand() > 0.5f);
                }

                Physics physics = other as Physics;

                if (physics != null)
                {
                    Vector3 force = other.Position - pos;
                    force.Normalize();
                    physics.ApplyForce(force * Knockback, 1.0f);
                }

                break;
            }

            case AttackMode.Ranged:
            {
                PlayNoise(other.LocalTransform.Translation);
                LaunchProjectile(pos, other.Position, faction);
                break;
            }
            }

            return(true);
        }