コード例 #1
0
 /*
 ============================================================================
 Check functions
 ============================================================================
 */
 public bool CheckRequirement(Combatant c)
 {
     bool check = false;
     if(StatusNeeded.STATUS_VALUE.Equals(this.statusNeeded) &&
         c.status[this.statID].CompareTo(this.value, this.comparison, this.setter, c))
     {
         check = true;
     }
     else if(StatusNeeded.ELEMENT.Equals(this.statusNeeded))
     {
         int element = c.GetElementDefence(this.statID);
         if((ValueCheck.EQUALS.Equals(this.comparison) && element == this.value) ||
             (ValueCheck.LESS.Equals(this.comparison) && element < this.value) ||
             (ValueCheck.GREATER.Equals(this.comparison) && element > this.value))
         {
             check = true;
         }
     }
     else if(StatusNeeded.SKILL.Equals(this.statusNeeded) && c.HasSkill(this.statID, 0))
     {
         check = true;
     }
     else if(StatusNeeded.RACE.Equals(this.statusNeeded) && c.raceID == this.statID)
     {
         check = true;
     }
     else if(StatusNeeded.SIZE.Equals(this.statusNeeded) && c.sizeID == this.statID)
     {
         check = true;
     }
     else if(StatusNeeded.LEVEL.Equals(this.statusNeeded))
     {
         int lvl = c.currentLevel;
         if(this.classLevel) lvl = c.currentClassLevel;
         if((ValueCheck.EQUALS.Equals(this.comparison) && lvl == this.value) ||
             (ValueCheck.LESS.Equals(this.comparison) && lvl < this.value) ||
             (ValueCheck.GREATER.Equals(this.comparison) && lvl > this.value))
         {
             check = true;
         }
     }
     return check;
 }
コード例 #2
0
ファイル: AIBehaviour.cs プロジェクト: hughrogers/RPGQuest
    /*
    ============================================================================
    Action handling functions
    ============================================================================
    */
    public BattleAction GetAction(Combatant c, int valid, Combatant[] allies, Combatant[] enemies)
    {
        BattleAction action = new BattleAction();
        bool found = false;
        bool targetEnemy = false;
        int difID = GameHandler.GetDifficulty();
        if(this.difficultyID <= difID)
        {
            for(int i=0; i<this.attackSelection.Length; i++)
            {
                if(this.actionDifficultyID[i] <= difID)
                {
                    if(valid == -2 && c.attackPartyTarget && DataHolder.BattleControl().HasPartyTarget())
                    {
                        action.targetID = DataHolder.BattleControl().GetPartyTargetID();
                    }
                    else if(valid == -2 && c.attackLastTarget && c.lastTargetBattleID >= 0 &&
                        DataHolder.BattleSystem().CheckForID(c.lastTargetBattleID, enemies, true))
                    {
                        action.targetID = c.lastTargetBattleID;
                    }
                    else
                    {
                        action.targetID = valid;
                    }
                    action.type = this.attackSelection[i];
                    // set up base attack
                    if(action.IsAttack() && !c.IsBlockAttack())
                    {
                        targetEnemy = true;
                        if(valid == -2)
                        {
                            if(c.aiNearestTarget)
                            {
                                action.targetID = c.GetNearestTarget(enemies);
                            }
                            else
                            {
                                action.targetID = c.GetRandomTarget(enemies);
                            }
                        }
                        found = true;
                    }
                    // set up skill
                    else if(action.IsSkill() && !c.IsBlockSkills() &&
                        c.HasSkill(this.useID[i], this.useLevel[i]) &&
                        DataHolder.Skill(this.useID[i]).CanUse(c, this.useLevel[i]-1))
                    {
                        action.useID = this.useID[i];
                        action.useLevel = this.useLevel[i]-1;
                        if(DataHolder.Skill(action.useID).TargetSelf())
                        {
                            action.targetID = c.battleID;
                        }
                        else if(DataHolder.Skill(action.useID).TargetNone())
                        {
                            action.targetID = BattleAction.NONE;
                            if(DataHolder.Skill(action.useID).targetRaycast.active)
                            {
                                GameObject target = null;
                                if(c.aiNearestTarget)
                                {
                                    if(DataHolder.Skill(action.useID).TargetEnemy())
                                    {
                                        target = c.GetNearestTargetObject(enemies);
                                    }
                                    else if(DataHolder.Skill(action.useID).TargetAlly())
                                    {
                                        target = c.GetNearestTargetObject(allies);
                                    }
                                }
                                else
                                {
                                    if(DataHolder.Skill(action.useID).TargetEnemy())
                                    {
                                        target = c.GetRandomTargetObject(enemies);
                                    }
                                    else if(DataHolder.Skill(action.useID).TargetAlly())
                                    {
                                        target = c.GetRandomTargetObject(allies);
                                    }
                                }
                                if(target != null)
                                {
                                    action.rayTargetSet = true;
                                    action.rayPoint = DataHolder.Skill(action.useID).targetRaycast.GetAIPoint(
                                            c.prefabInstance, target);
                                }
                            }
                        }
                        else if(DataHolder.Skill(action.useID).TargetAllyGroup() && c is Enemy)
                        {
                            action.targetID = BattleAction.ALL_ENEMIES;
                        }
                        else if(DataHolder.Skill(action.useID).TargetAllyGroup() && c is Character)
                        {
                            action.targetID = BattleAction.ALL_CHARACTERS;
                        }
                        else if(DataHolder.Skill(action.useID).TargetEnemyGroup() && c is Enemy)
                        {
                            action.targetID = BattleAction.ALL_CHARACTERS;
                            targetEnemy = true;
                        }
                        else if(DataHolder.Skill(action.useID).TargetEnemyGroup() && c is Character)
                        {
                            action.targetID = BattleAction.ALL_ENEMIES;
                            targetEnemy = true;
                        }
                        else if(DataHolder.Skill(action.useID).TargetSingleAlly())
                        {
                            if(valid == -2 || !DataHolder.BattleSystem().CheckForID(valid, allies,
                                !DataHolder.Skill(action.useID).level[action.useLevel].revive))
                            {
                                if(c.aiNearestTarget)
                                {
                                    action.targetID = c.GetNearestTarget(allies);
                                }
                                else
                                {
                                    action.targetID = c.GetRandomTarget(allies);
                                }
                            }
                        }
                        else if(DataHolder.Skill(action.useID).TargetSingleEnemy())
                        {
                            if(valid == -2 || !DataHolder.BattleSystem().CheckForID(valid, enemies, true))
                            {
                                if(c.aiNearestTarget)
                                {
                                    action.targetID = c.GetNearestTarget(enemies);
                                }
                                else
                                {
                                    action.targetID = c.GetRandomTarget(enemies);
                                }
                            }
                            targetEnemy = true;
                        }
                        found = true;
                    }
                    // set up item
                    else if(action.IsItem() && !c.IsBlockItems() &&
                        (!(c is Character) || GameHandler.HasItem(this.useID[i], 1)))
                    {
                        action.useID = this.useID[i];
                        if(DataHolder.Item(action.useID).TargetSelf())
                        {
                            action.targetID = c.battleID;
                        }
                        else if(DataHolder.Item(action.useID).TargetNone())
                        {
                            action.targetID = BattleAction.NONE;
                            if(DataHolder.Item(action.useID).targetRaycast.active)
                            {
                                GameObject target = null;
                                if(c.aiNearestTarget)
                                {
                                    if(DataHolder.Item(action.useID).TargetEnemy())
                                    {
                                        target = c.GetNearestTargetObject(enemies);
                                    }
                                    else if(DataHolder.Item(action.useID).TargetAlly())
                                    {
                                        target = c.GetNearestTargetObject(allies);
                                    }
                                }
                                else
                                {
                                    if(DataHolder.Item(action.useID).TargetEnemy())
                                    {
                                        target = c.GetRandomTargetObject(enemies);
                                    }
                                    else if(DataHolder.Item(action.useID).TargetAlly())
                                    {
                                        target = c.GetRandomTargetObject(allies);
                                    }
                                }
                                if(target != null)
                                {
                                    action.rayTargetSet = true;
                                    action.rayPoint = DataHolder.Item(action.useID).targetRaycast.GetAIPoint(
                                            c.prefabInstance, target);
                                }
                            }
                        }
                        else if(DataHolder.Item(action.useID).TargetAllyGroup() && c is Enemy)
                        {
                            action.targetID = BattleAction.ALL_ENEMIES;
                        }
                        else if(DataHolder.Item(action.useID).TargetAllyGroup() && c is Character)
                        {
                            action.targetID = BattleAction.ALL_CHARACTERS;
                        }
                        else if(DataHolder.Item(action.useID).TargetEnemyGroup() && c is Enemy)
                        {
                            action.targetID = BattleAction.ALL_CHARACTERS;
                            targetEnemy = true;
                        }
                        else if(DataHolder.Item(action.useID).TargetEnemyGroup() && c is Character)
                        {
                            action.targetID = BattleAction.ALL_ENEMIES;
                            targetEnemy = true;
                        }
                        else if(DataHolder.Item(action.useID).TargetSingleAlly())
                        {
                            if(valid == -2 || !DataHolder.BattleSystem().CheckForID(valid, allies,
                                !DataHolder.Item(action.useID).revive))
                            {
                                if(DataHolder.BattleSystem().IsRealTime())
                                {
                                    action.targetID = c.GetNearestTarget(allies);
                                }
                                else
                                {
                                    action.targetID = c.GetRandomTarget(allies);
                                }
                            }
                        }
                        else if(DataHolder.Item(action.useID).TargetSingleEnemy())
                        {
                            if(valid == -2 || !DataHolder.BattleSystem().CheckForID(valid, enemies, true))
                            {
                                if(DataHolder.BattleSystem().IsRealTime())
                                {
                                    action.targetID = c.GetNearestTarget(enemies);
                                }
                                else
                                {
                                    action.targetID = c.GetRandomTarget(enemies);
                                }
                            }
                            targetEnemy = true;
                        }
                        found = true;
                    }
                    else if(action.IsDefend() && !c.IsBlockDefend())
                    {
                        action.targetID = c.battleID;
                        found = true;
                    }
                    // set up escape
                    else if(action.IsEscape() && !c.IsBlockEscape())
                    {
                        action.targetID = c.battleID;
                        found = true;
                    }
                    else if(action.IsDeath() || action.IsNone())
                    {
                        action.targetID = c.battleID;
                        found = true;
                    }

                    // check active time
                    if(found)
                    {
                        if((DataHolder.BattleSystem().IsActiveTime() &&
                            c.usedTimeBar+action.GetTimeUse() > DataHolder.BattleSystem().maxTimebar) ||
                            (targetEnemy && enemies.Length == 0))
                        {
                            found = false;
                            targetEnemy = false;
                            action = new BattleAction();
                        }
                        else break;
                    }
                }
            }
        }

        if(!found) action = null;
        return action;
    }