示例#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>
    /// Cancel task.
    /// </summary>
    /// <returns>true</returns>
    /// <c>false</c>
    public override bool CancelTask()
    {
        AttackManagerMetaData data = AttackManagerMetaData.Load();

        if (data.CancelAttack(_taskId))
        {
            base.CancelTask();

            return(true);
        }

        return(false);
    }
示例#3
0
    /// <summary>
    /// Checks the task complete.
    /// </summary>
    /// <returns>The task complete.</returns>
    IEnumerator CheckTaskComplete()
    {
        AttackManagerMetaData data = AttackManagerMetaData.Load();

        AttackInfo info = null;

        while ((info = data.IsAttackTaskComplete(_taskId)) == null)
        {
            yield return(new WaitForSeconds(1f));
        }

        _attackResult = info.result;

        CompleteTask();
    }
示例#4
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));
        }
    }
示例#5
0
    public static AttackManagerMetaData Load(bool processing = false)
    {
        if (!SaveLoadManager.SharedManager.IsFileExist <AttackManagerMetaData>())
        {
            AttackManagerMetaData newData = new AttackManagerMetaData();

            newData.Save();

            return(newData);
        }

        AttackManagerMetaData data = SaveLoadManager.SharedManager.Load <AttackManagerMetaData> ();

        if (processing)
        {
            data.ProcessData();

            data.Save();
        }


        return(data);
    }