Esempio n. 1
0
        private static ConsoleKeyAndChoice GetPresetCkiAndChoice(AgentActionChoice choice)
        {
            if (choice.Category != SampleGame.Vals.CombatCategory.TopLevelAction)
            {
                return(null);
            }

            ConsoleKeyInfo cki;

            //some toplevel actions have an .Action
            if (choice.Action == SampleGame.Vals.CombatAction.AttackWeaponMelee)
            {
                cki = new ConsoleKeyInfo('m', ConsoleKey.M, false, false, false);
            }
            if (choice.Action == SampleGame.Vals.CombatAction.AttackWeaponRanged)
            {
                cki = new ConsoleKeyInfo('f', ConsoleKey.F, false, false, false);
            }
            if (choice.Action == SampleGame.Vals.CombatAction.DoNothing)
            {
                cki = new ConsoleKeyInfo('n', ConsoleKey.N, false, false, false);
            }
            if (choice.Action == SampleGame.Vals.CombatAction.RunAway)
            {
                cki = new ConsoleKeyInfo('r', ConsoleKey.R, false, false, false);
            }

            //other top levels are inferred by .NextCategory.
            if (choice.NextCategory == SampleGame.Vals.CombatCategory.AllMelee)
            {
                cki = new ConsoleKeyInfo('m', ConsoleKey.M, false, true, false);
            }
            if (choice.NextCategory == SampleGame.Vals.CombatCategory.AllRanged)
            {
                cki = new ConsoleKeyInfo('f', ConsoleKey.F, false, true, false);
            }
            if (choice.NextCategory == SampleGame.Vals.CombatCategory.AllSpells)
            {
                cki = new ConsoleKeyInfo('c', ConsoleKey.C, false, true, false);
            }
            if (choice.NextCategory == SampleGame.Vals.CombatCategory.AllStances)
            {
                cki = new ConsoleKeyInfo('s', ConsoleKey.S, false, true, false);
            }

            return(new ConsoleKeyAndChoice {
                Cki = cki, Choice = choice
            });
        }
Esempio n. 2
0
        public static CombatChoicesAndTargets GetPossibleActions(EcsRegistrar rgs, long globalId, long agentId, List <long> battlefieldEntityIds)
        {
            var possibleCombatActions = new CombatChoicesAndTargets();

            var naturalWeaponsMap = rgs.GetPartSingle <Parts.NaturalWeaponsMap>(globalId);

            var agentAnatomy = rgs.GetPartSingle <Parts.Anatomy>(agentId);

            //var agentWieldingDisabled = agentAnatomyModifers
            //    .Where(m => m.EquipmentSlotDisabled == Vals.BodyEquipmentSlots.WieldObjectAppendage)
            //    .Select(m => m.EquipmentSlotDisabled)
            //    .ToList();

            var agentWieldedIds = agentAnatomy.SlotsEquipped
                                  .Where(s => s.Key == Vals.BodySlots.WieldHandLeft || s.Key == Vals.BodySlots.WieldHandRight || s.Key == Vals.BodySlots.WieldTwoHanded)
                                  .Select(s => s.Value)
                                  .ToList();
            var agentWieldedIdToWeaponEntityName = agentWieldedIds
                                                   .Where(id => id != 0)
                                                   .Distinct()
                                                   .Select(id => new { Id = id, Name = rgs.GetPartSingle <Parts.EntityName>(id) })
                                                   .ToDictionary(n => n.Id, n => n.Name);

            var agentNaturalWeaponSlots = naturalWeaponsMap.NaturalWeaponSets[agentAnatomy.NaturalWeaponsCategory];
            //MWCTODO: some magic happens here and we find out a wristblade or a laser eye has been equipped, and add that to the slots.
            // also any quickslots that might have attack items in them. we want quickslots. maybe a wristblade or a laser eye automatically adds a new, fixed quickslot for itself? i like this idea upon first think!
            var recordedIds = new HashSet <long>();

            foreach (var slot in agentNaturalWeaponSlots.Keys)
            {
                var weaponId = agentAnatomy.SlotsEquipped[slot];
                if (weaponId == 0L)
                {
                    weaponId = agentNaturalWeaponSlots[slot];
                }

                if (recordedIds.Contains(weaponId))
                {
                    continue;
                }

                var weapon = Bundle.GetWeaponBundle(rgs, weaponId);
                var choice = new AgentActionChoice
                {
                    AgentId        = agentId,
                    Category       = Vals.CombatCategory.TopLevelAction,
                    Description    = $"Melee {weapon.EntityName.GeneralName}",
                    Action         = Vals.CombatAction.AttackWeaponMelee,
                    WeaponBodySlot = slot,
                    WeaponEntityId = weaponId,
                    NextCategory   = Vals.CombatCategory.MeleeTarget
                };

                possibleCombatActions.Choices.Add(choice);
                recordedIds.Add(weaponId);
            }

            foreach (long id in battlefieldEntityIds)
            {
                if (id == agentId)
                {
                    continue;
                }

                var entityName  = rgs.GetPartSingleOrDefault <Parts.EntityName>(id);
                var entityAgent = rgs.GetPartSingleOrDefault <Parts.Agent>(id);

                if (entityName == null || entityAgent == null)
                {
                    continue;
                }

                if (entityAgent.CombatStatusTags.Intersect(Vals.CombatStatusTag.CombatTerminalStatuses).Any())
                {
                    continue;
                }

                possibleCombatActions.MeleeTargets.Add(id, entityName.ProperName);
            }

            //add stances
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId     = agentId,
                Category    = Vals.CombatCategory.AllStances,
                Description = "Stance (Defensive)",
                Action      = Vals.CombatAction.StanceDefensive
            });
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId     = agentId,
                Category    = Vals.CombatCategory.AllStances,
                Description = "Stance (Stand Ground)",
                Action      = Vals.CombatAction.StanceStandGround
            });
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId     = agentId,
                Category    = Vals.CombatCategory.AllStances,
                Description = "Stance (Aggressive)",
                Action      = Vals.CombatAction.StanceAggressive
            });

            //add top-level choices that we know are present: note that we already did NextCategory = primary-melee because the description there is context dependent.
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId      = agentId,
                Category     = Vals.CombatCategory.TopLevelAction,
                Description  = "All Melee Options",
                NextCategory = Vals.CombatCategory.AllMelee
            });
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId      = agentId,
                Category     = Vals.CombatCategory.TopLevelAction,
                Description  = "Change Stance",
                NextCategory = Vals.CombatCategory.AllStances
            });
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId     = agentId,
                Category    = Vals.CombatCategory.TopLevelAction,
                Description = "Run Away",
                Action      = Vals.CombatAction.RunAway
            });
            possibleCombatActions.Choices.Add(new AgentActionChoice
            {
                AgentId     = agentId,
                Category    = Vals.CombatCategory.TopLevelAction,
                Description = "Do Nothing",
                Action      = Vals.CombatAction.DoNothing
            });


            return(possibleCombatActions);
        }
Esempio n. 3
0
        //we want the choices to stay as consistent as possible from round to round. if the same action was visible previously, keep it.
        private static ConsoleKeyAndChoice GetEstablishedKeyAndChoice(List <ConsoleKeyAndChoice> establishedChoices, AgentActionChoice choice)
        {
            var establishedChoice = establishedChoices.SingleOrDefault(c => c.Choice.Category == choice.Category &&
                                                                       c.Choice.Action == choice.Action && c.Choice.WeaponEntityId == choice.WeaponEntityId && c.Choice.WeaponBodySlot == c.Choice.WeaponBodySlot);

            if (establishedChoice == null)
            {
                return(null);
            }

            //update the description, it could have changed.
            establishedChoice.Choice.Description = choice.Description;

            return(establishedChoice);
        }