示例#1
0
        private ProcessResult PostProcess(FullCombatCharacter source, List <FullCombatCharacter> target, CombatData combatData, List <IEffect> effects)
        {
            //Set next attack time etc.
            if (cooldown != string.Empty)
            {
                combatData.cooldowns.Add(new CooldownModel
                {
                    character = source.name,
                    name      = cooldown,
                    time      = (source.nextAttackTime + cooldownDuration)
                });
            }

            GeneralProcessor.calculateNextAttackTime(source, attackTimeCoefficient, combatData);

            if (oncePerRest != string.Empty)
            {
                source.usedAbilities.Add(oncePerRest);
            }

            if (mpCost != 0)
            {
                source.mp = source.mp - mpCost;
            }

            return(ProcessResult.Normal);
        }
示例#2
0
        //Basic Goblin, only attacks

        public static List <IEffect> getCommand(FullCombatCharacter source, List <FullCombatCharacter> targets, CombatData combatData)
        {
            List <IEffect>      effects = new List <IEffect>();
            FullCombatCharacter target  = BasicAbilityProcessing.identifyWeakestTarget(targets);
            int dmg = (int)((source.strength * 5 / target.vitality));

            target.inflictDamage(ref dmg);
            effects.Add(new Effect(EffectTypes.DealDamage, target.combatUniq, string.Empty, dmg));
            effects.Add(new Effect(EffectTypes.Message, 0, source.name + " has attacked " + target.name + " for " + dmg.ToString() + " damage!", 0));
            GeneralProcessor.calculateNextAttackTime(source, 1.0f);

            return(effects);
        }
示例#3
0
        public static List <IEffect> getCommand(FullCombatCharacter source, List <FullCombatCharacter> targets, CombatData combatData)
        {
            List <IEffect>      effects     = new List <IEffect>();
            float               coefficient = 1.0f;
            FullCombatCharacter target      = BasicAbilityProcessing.identifyWeakestTarget(targets);
            int dmg = (int)((CombatCalculator.getNormalAttackValue(source) * 5 / target.vitality));

            if (target.inflictDamage(ref dmg) == FullCombatCharacter.HitEffect.Unbalance)
            {
                coefficient = coefficient * 2;
            }
            effects.Add(new Effect(EffectTypes.Attack, source.combatUniq, string.Empty, 0));
            effects.Add(new Effect(EffectTypes.DealDamage, target.combatUniq, string.Empty, dmg));
            effects.Add(new Effect(EffectTypes.Message, 0, source.name + " has attacked " + target.name + " for " + dmg.ToString() + " damage!", 0));
            GeneralProcessor.calculateNextAttackTime(source, coefficient, combatData);

            return(effects);
        }
示例#4
0
        public Combat(PlayerModels.PlayerModel playerModel, string map, int encounterSelection, Func <float> initiativeCalculator, Action onGameOver, Action onUpdate, Action <CombatEndType> onCombatComplete)
        {
            int currentUniq = 1;

            this.playerModel = playerModel;
            uniqBridge       = new Dictionary <int, int>();
            pcs                   = new Dictionary <int, FullCombatCharacter>();
            npcs                  = new Dictionary <int, FullCombatCharacter>();
            currentEffects        = new List <IEffect>();
            currentCharacter      = new FullCombatCharacter();
            this.onGameOver       = onGameOver;
            this.onUpdate         = onUpdate;
            this.onCombatComplete = onCombatComplete;
            this.map              = map;
            bool canFlee = true;

            List <PlayerModels.Models.PartyCharacterModel> partyCharacterModels = PlayerModels.PlayerDataManager.getCurrentPartyPartyStats(playerModel);
            List <int> characterUniqs = new List <int>();

            foreach (PlayerModels.Models.PartyCharacterModel pcm in partyCharacterModels)
            {
                characterUniqs.Add(pcm.characterUniq);
            }
            List <PlayerModels.Models.CharacterModel> characterModels = PlayerModels.PlayerDataManager.getCurrentParty(playerModel, characterUniqs);
            bool hasPreviousCombatModels = false;

            if (playerModel.currentCombat == null)
            {
                combatCharacterModels                 = new List <PlayerModels.CombatDataModels.CombatCharacterModel>();
                combatNPCModels                       = new List <CombatCharacterModel>();
                playerModel.currentCombat             = new CombatModel();
                playerModel.currentCombat.currentTime = 0;
                playerModel.currentCombat.pcs         = combatCharacterModels;
                playerModel.currentCombat.npcs        = combatNPCModels;
            }
            else
            {
                combatCharacterModels   = playerModel.currentCombat.pcs;
                combatNPCModels         = playerModel.currentCombat.npcs;
                hasPreviousCombatModels = true;
            }

            foreach (int characterUniq in characterUniqs)
            {
                string name           = string.Empty;
                int    hp             = 0;
                int    maxHP          = 0;
                int    mp             = 0;
                int    maxMP          = 0;
                int    turnOrder      = 0;
                string classType      = string.Empty;
                int    level          = 0;
                int    strength       = 0;
                int    vitality       = 0;
                int    agility        = 0;
                int    intellect      = 0;
                int    wisdom         = 0;
                int    nextAttackTime = 0;
                int    classLevel     = 0;
                int    combatUniq     = currentUniq;
                List <CombatModificationsModel> mods = new List <CombatModificationsModel>();
                List <string> usedAbilities          = new List <string>();
                uniqBridge.Add(currentUniq, characterUniq);

                foreach (PlayerModels.Models.CharacterModel cm in characterModels)
                {
                    if (cm.uniq == characterUniq)
                    {
                        name      = cm.name;
                        maxHP     = cm.stats.maxHP;
                        maxMP     = cm.stats.maxMP;
                        classType = cm.currentClass;
                        level     = cm.lvl;
                        strength  = cm.stats.strength;
                        vitality  = cm.stats.vitality;
                        agility   = cm.stats.agility;
                        intellect = cm.stats.intellect;
                        wisdom    = cm.stats.wisdom;

                        foreach (PlayerModels.Models.CharacterClassModel ccm in cm.characterClasses)
                        {
                            if (ccm.className == classType)
                            {
                                classLevel = ccm.lvl;
                            }
                        }
                    }
                }

                foreach (PlayerModels.Models.PartyCharacterModel pcm in partyCharacterModels)
                {
                    if (pcm.characterUniq == characterUniq)
                    {
                        hp            = pcm.hp;
                        mp            = pcm.mp;
                        usedAbilities = (pcm.usedAbilities == null ? new List <string>() : pcm.usedAbilities);
                    }
                }

                nextAttackTime = GeneralProcessor.calculateNextAttackTime(0, initiativeCalculator(), agility);

                if (hasPreviousCombatModels)
                {
                    foreach (CombatCharacterModel ccm in combatCharacterModels)
                    {
                        if (ccm.characterUniq == characterUniq)
                        {
                            nextAttackTime = ccm.nextAttackTime;
                            hp             = ccm.stats.hp;
                            mp             = ccm.stats.mp;
                            combatUniq     = ccm.combatUniq;
                        }
                    }
                }
                else
                {
                    combatCharacterModels.Add(new PlayerModels.CombatDataModels.CombatCharacterModel()
                    {
                        characterUniq = characterUniq,
                        stats         = new PlayerModels.CombatDataModels.TemporaryCombatStatsModel()
                        {
                            hp = hp, mp = mp
                        },
                        nextAttackTime = nextAttackTime,
                        combatUniq     = combatUniq
                    });
                }

                pcs.Add(characterUniq, new FullCombatCharacter()
                {
                    name           = name,
                    maxHP          = maxHP,
                    hp             = hp,
                    maxMP          = maxMP,
                    mp             = mp,
                    characterUniq  = characterUniq,
                    combatUniq     = currentUniq,
                    className      = classType,
                    classLevel     = classLevel,
                    level          = level,
                    strength       = strength,
                    vitality       = vitality,
                    intellect      = intellect,
                    agility        = agility,
                    wisdom         = wisdom,
                    nextAttackTime = nextAttackTime,
                    mods           = new List <CombatModificationsModel>(),
                    usedAbilities  = usedAbilities
                });

                combatCharacterModels[combatCharacterModels.Count - 1].mods = pcs[characterUniq].mods;

                currentUniq++;
            }

            if (hasPreviousCombatModels) //Combat was already initialized previously, just load the previous combatants
            {
                foreach (CombatCharacterModel ccm in combatNPCModels)
                {
                    int    hp             = ccm.stats.hp;
                    int    mp             = ccm.stats.mp;
                    string name           = ccm.name;
                    int    nextAttackTime = ccm.nextAttackTime;
                    List <CombatModificationsModel> mods = ccm.mods;
                    List <string> usedAbilities          = new List <string>();

                    MapDataClasses.MapDataClasses.Enemy enemy = MapDataClasses.MapDataManager.getEnemy(map, ccm.classType);

                    if (!this.npcs.ContainsKey(currentUniq))
                    {
                        this.npcs.Add(currentUniq, new FullCombatCharacter()
                        {
                            name           = name,
                            hp             = hp,
                            maxHP          = enemy.maxHP,
                            mp             = mp,
                            maxMP          = enemy.maxMP,
                            characterUniq  = 0,
                            combatUniq     = currentUniq,
                            className      = enemy.type,
                            level          = enemy.level,
                            strength       = enemy.strength,
                            vitality       = enemy.vitality,
                            agility        = enemy.agility,
                            intellect      = enemy.intellect,
                            wisdom         = enemy.wisdom,
                            nextAttackTime = nextAttackTime,
                            mods           = mods,
                            usedAbilities  = usedAbilities
                        });
                    }

                    currentUniq++;
                }
            }
            else //Generate a new encounter based on the map type
            {
                Encounter encounter = MapDataClasses.MapDataManager.getEncounter(this.playerModel.getActiveParty().location, playerModel.rootX, playerModel.rootY, encounterSelection);
                currentEffects.Add(new Effect(EffectTypes.Message, 0, encounter.message, 0));
                combatNPCModels = new List <PlayerModels.CombatDataModels.CombatCharacterModel>();
                canFlee         = encounter.canFlee;
                foreach (MapDataClasses.MapDataClasses.Enemy enemy in encounter.enemies)
                {
                    int nextAttackTime = GeneralProcessor.calculateNextAttackTime(0, initiativeCalculator(), enemy.agility);
                    int hp             = enemy.maxHP;
                    int mp             = enemy.maxMP;
                    int combatUniq     = currentUniq;
                    List <CombatModificationsModel> mods = new List <CombatModificationsModel>();
                    List <string> usedAbilities          = new List <string>();

                    this.npcs.Add(currentUniq, new FullCombatCharacter()
                    {
                        name           = enemy.name,
                        hp             = hp,
                        maxHP          = enemy.maxHP,
                        mp             = mp,
                        maxMP          = enemy.maxMP,
                        characterUniq  = 0,
                        combatUniq     = currentUniq,
                        className      = enemy.type,
                        level          = enemy.level,
                        strength       = enemy.strength,
                        vitality       = enemy.vitality,
                        agility        = enemy.agility,
                        intellect      = enemy.intellect,
                        wisdom         = enemy.wisdom,
                        nextAttackTime = nextAttackTime,
                        mods           = mods,
                        usedAbilities  = usedAbilities
                    });


                    this.combatNPCModels.Add(new PlayerModels.CombatDataModels.CombatCharacterModel()
                    {
                        name  = enemy.name,
                        stats = new PlayerModels.CombatDataModels.TemporaryCombatStatsModel()
                        {
                            hp = hp,
                            mp = mp
                        },
                        nextAttackTime = nextAttackTime,
                        combatUniq     = currentUniq,
                        characterUniq  = 0,
                        classType      = enemy.type,
                        mods           = this.npcs[currentUniq].mods
                    });

                    currentUniq++;
                }
            }

            playerModel.currentCombat.npcs = combatNPCModels;
            if (combatNPCModels.Count == 0)
            {
                throw new Exception("No NPCs were loaded :(");
            }

            calculateTurnOrder();
            this.combatData = new CombatData(playerModel.currentCombat, canFlee);

            if (!this.combatData.combatInitalized)
            {
                foreach (int key in pcs.Keys) //Check for initial code
                {
                    FullCombatCharacter fcc        = pcs[key];
                    List <IEffect>      newEffects = GeneralProcessor.initialExecute(fcc)(getAllPcsAsList(), getAllNpcsAsList(), this.combatData);
                    currentEffects.AddRange(newEffects);
                }

                this.combatData.combatInitalized = true;
            }
            calculateTurn(false);
        }