示例#1
0
        private void processBattleResults(int winner, int loser, int fightZone, Commander command)
        {
            Console.WriteLine("process battle results");

            lock (_commanders)
            {
                command.PositionLocked = true;
                _radialUI = null;
                clearProgressAndDialog();

                Action endCallback;
                List<Commander> commandsToMove = new List<Commander>();
                List<Vector2> starts, ends;
                starts = new List<Vector2>();
                ends = new List<Vector2>();

                if (command.Owner == winner)
                {
                    _map.setZoneOwner(fightZone, command.Owner);

                    foreach (Commander looserCommand in _commanders)
                    {
                        if (looserCommand.Owner == loser
                            && _map.getZoneAt(looserCommand.Position) == fightZone)
                        {
                            commandsToMove.Add(looserCommand);

                            int newZone = _map.getClosestZoneOfOwner(loser, fightZone);
                            looserCommand.CurrentZone = newZone;
                            ends.Add(_map.getCenterOfZone(newZone));
                            starts.Add(looserCommand.Position);
                            looserCommand.PositionLocked = true;
                        }
                    }

                    endCallback = delegate()
                    {
                        ServerCom.Instance.Socket.Emit("territoryWon", new
                        {
                            zone = fightZone - 1,
                            owner = command.Owner
                        });

                        UpdateAction = emptyUpdate;
                        ServerCom.Instance.sendSimpleMessage("nextPhase3");
                        Console.WriteLine("\n\n send nextPhase3\n");
                    };
                }
                else
                {
                    Console.WriteLine("\nbattle lost, fall back to " + command.AttackStartZone + "\n");
                    //put attacker back to his start zone
                    //command.Position = _map.getCenterOfZone(command.AttackStartZone);

                    commandsToMove.Add(command);
                    starts.Add(command.Position);
                    command.CurrentZone = command.AttackStartZone;
                    ends.Add(_map.getCenterOfZone(command.AttackStartZone));

                    endCallback = delegate()
                    {
                        UpdateAction = emptyUpdate;
                        ServerCom.Instance.sendSimpleMessage("nextPhase3");
                        Console.WriteLine("\n\n send nextPhase3\n");
                    };
                }

                _timeSinceAnimStart = 0f;
                UpdateAction = delegate(float dt)
                {
                    animCommanderMoveUpdate(dt, endCallback, starts, ends, commandsToMove);
                };
            }
        }
示例#2
0
        private void cheatAddCommanders()
        {
            long lastAddedTag = _firstTagValue;
            Random rand = new Random();

            while (_commanders.Count < MyGame.NUMBER_OF_PLAYER * 2)

            {
                int owner = getOwnerForTag(lastAddedTag);
                int zone = rand.Next(1, 17); //1..16
                if (zone >= 0 && _map.getZoneOwner(zone) == owner)
                {
                    Commander command = new Commander(_commanderHighlight);
                    command.Position = _map.getCenterOfZone(zone);
                    command.CurrentZone = zone;
                    command.Owner = owner;
                    command.TagValue = lastAddedTag;

                    _commanders.Add(command);
                    ++lastAddedTag;
                }
            }
        }
示例#3
0
        private void onBattleResult(SocketIOClient.Messages.IMessage data, Commander command, int fightZone)
        {
            Console.WriteLine("\nonBattleResult\n");

            Console.WriteLine("\n" + data.Json.ToJsonString() + "\n");

            BattleResult br;
            BattleResultRoot root = Newtonsoft.Json.JsonConvert.DeserializeObject<BattleResultRoot>(data.Json.ToJsonString());

            br = root.args[0];

            Console.WriteLine("winner : " + br.winner + " looser : " + br.loser + " attacker : " + command.Owner + " fightzone : " + fightZone);

            //Display answers

            List<OrderedAnswer> answers = new List<OrderedAnswer>();
            OrderedAnswer answerWin = new OrderedAnswer();
            answerWin.id = br.winner;
            answerWin.time = 0f;
            answerWin.value = br.winVal;

            OrderedAnswer answerLoss = new OrderedAnswer();
            answerLoss.id = br.loser;
            answerLoss.time = 0f;
            answerLoss.value = br.lossVal;

            answers.Add(answerWin);
            answers.Add(answerLoss);

            _radialUI = null;

            initAnswerUI(answers);

            clearProgressAndDialog();

            Action endCallback = delegate() { processBattleResults(br.winner, br.loser, fightZone, command); };

            _timeSinceAnswerDisplayStart = 0f;
            UpdateAction = delegate(float dt) {answersDisplayUpdate(dt, endCallback);};
        }
示例#4
0
        private void addCommanderTag(TouchPoint touch, int owner)
        {
            foreach (Commander commander in _commanders)
            {
                if (commander.TagValue == touch.Tag.Value)
                {
                    commander.Position = Utils.touchPointToV2(touch);
                    commander.CurrentZone = _map.getZoneAt(commander.Position);
                    return; //Our work here is done
                }
            }

            //if the tag does not already exist
            Commander command = new Commander(_commanderHighlight);
            command.Position = Utils.touchPointToV2(touch);
            command.Owner = owner;
            command.TagValue = touch.Tag.Value;

            _commanders.Add(command);
        }