コード例 #1
0
        public override CommandResult Execute()
        {
            Entity defender;

            if (target.Actor != null)
            {
                defender = target.Actor;
            }
            else
            {
                defender = null;
            }

            SpeciesDefinition species = Entity.GetComponent <Species>().SpeciesDef;

            foreach (BodyPart part in species.Parts)
            {
                if (part.Melee == null)
                {
                    continue;
                }

                if (part.Melee.Attacks == null)
                {
                    continue;
                }

                foreach (Attack atk in part.Melee.Attacks)
                {
                    if (atk.Accuracy < Random.Range(0, 101))
                    {
                        Locator.Log.Send(
                            Verbs.Miss(Entity, defender), Color.grey);
                        continue;
                    }

                    if (defender != null)
                    {
                        Hit hit = new Hit(atk.Damages);
                        Locator.Log.Send(
                            Verbs.Hit(Entity, defender, hit), Color.white);
                        defender.TakeHit(Entity, hit);
                    }
                }
            }

            return(CommandResult.Succeeded);
        }
コード例 #2
0
        public override CommandResult Invoke(Entity caster, Cell target)
        {
            if (target == null)
            {
                throw new NotImplementedException("Target cell needed.");
            }

            Cell affected = Bresenhams.GetLine(
                caster.Level, caster.Cell, target).ElementAtOrLast(Range);

            Entity enemy = affected.Actor;

            if (enemy == null)
            {
                Locator.Audio.Buffer(
                    Assets.Audio["SFX_Toss"],
                    affected.Position.ToVector3());
                Locator.Log.Send(
                    $"{Strings.Subject(caster, true)}" +
                    $" {Verbs.Swing(caster)} at nothing.",
                    Color.grey);
                return(CommandResult.Succeeded);
            }

            if (Accuracy < Random.Range(0, 101))
            {
                Locator.Log.Send(
                    Verbs.Miss(caster, enemy), Color.grey);
                return(CommandResult.Succeeded);
            }

            Locator.Audio.Buffer(
                Assets.Audio["SFX_Punch"],
                affected.Position.ToVector3());

            Hit hit = new Hit(Damages);

            Locator.Log.Send(Verbs.Hit(caster, enemy, hit), Color.white);
            enemy.TakeHit(caster, hit);
            return(CommandResult.Succeeded);
        }