Пример #1
0
    /*
     * public bool AttackPlayer(string playerId, int sentUnit)
     * {
     *      AIPlayer aiPlayer = GetAIPlayer (playerId);
     *
     *      if(aiPlayer != null)
     *      {
     *              AttackManagerMetaData data = AttackManagerMetaData.Load();
     *
     *              string taskId = GenerateTaskId();
     *
     *              if(data.AddAttackTask(taskId, aiPlayer.playerId, aiPlayer.playerName, aiPlayer.totalCombatUnit, sentUnit, aiPlayer.attackDuration))
     *              {
     *                      AttackTask task = AttackTask.CreateTask(taskId, aiPlayer.playerId, aiPlayer.playerName, aiPlayer.totalCombatUnit, OnAttackTaskComplete, null, aiPlayer.attackDuration);
     *
     *                      _attackTasks.Add(task);
     *
     *                      TaskManager.Instance.AddTask(task);
     *
     *                      EventManager.GetInstance().ExecuteEvent<EventNewAttack>(new EventNewAttack(task));
     *
     *                      return true;
     *              }
     *      }
     *      else
     *      {
     *              Debug.LogError("Attack player with id "+playerId+" not exist");
     *      }
     *
     *      return false;
     * }
     */

    /// <summary>
    /// Attacks player.
    /// </summary>
    /// <returns><c>true</c>, if player was attacked, <c>false</c> otherwise.</returns>
    /// <param name="playerId">Player identifier.</param>
    /// <param name="sentUnit">Sent unit.</param>
    public bool AttackPlayer(string playerId, Dictionary <CombatUnitType, int> sentUnit)
    {
        //todo:send unit

        AIPlayer aiPlayer = GetAIPlayer(playerId);

        if (aiPlayer != null)
        {
            AttackManagerMetaData data = AttackManagerMetaData.Load();

            string taskId = GenerateTaskId();

            //attacker(player) unit
            Dictionary <CombatUnit, int> dic = new Dictionary <CombatUnit, int>();

            foreach (CombatUnitType type in sentUnit.Keys)
            {
                if (sentUnit[type] > 0)
                {
                    CombatUnit unit = CombatUnitManager.Instance.GetCombatUnitInfoByType(type);

                    dic.Add(unit, sentUnit[type]);
                }
            }

            Dictionary <ResourceType, float> resoruceAward = new Dictionary <ResourceType, float>();

            for (int i = 0; i < aiPlayer.resourceAwardType.Count; i++)
            {
                resoruceAward.Add(aiPlayer.resourceAwardType[i], aiPlayer.resourceAwardAmount[i]);
            }

            if (data.AddAttackTask(taskId, aiPlayer.playerId, aiPlayer.playerName, aiPlayer.GetPlayerCombatUnitInfo(), dic, aiPlayer.attackDuration, resoruceAward))
            {
                AttackTask task = AttackTask.CreateTask(taskId, aiPlayer.playerId, aiPlayer.playerName, aiPlayer.GetPlayerCombatUnitInfo(), dic,
                                                        OnAttackTaskComplete, null, aiPlayer.attackDuration);

                _attackTasks.Add(task);

                TaskManager.Instance.AddTask(task);

                EventManager.GetInstance().ExecuteEvent <EventNewAttack>(new EventNewAttack(task));

                return(true);
            }
        }
        else
        {
            Debug.LogError("Attack player with id " + playerId + " not exist");
        }

        return(false);
    }
Пример #2
0
    /// <summary>
    /// Fetch data from meta data.
    /// </summary>
    void DoFetchData()
    {
        AttackManagerMetaData data = AttackManagerMetaData.Load(true);

        AttackInfo[] infos = data.GetAttackInfo();

        for (int i = 0; i < infos.Length; i++)
        {
            AttackInfo info = infos[i];

            AttackTask task = AttackTask.CreateTask(info.taskId, info.targetId, info.targetName, info.targetUnit, info.attackerUnit,
                                                    OnAttackTaskComplete, null, info.duration);

            _attackTasks.Add(task);

            TaskManager.Instance.AddTask(task);

            EventManager.GetInstance().ExecuteEvent <EventNewAttack>(new EventNewAttack(task));
        }
    }