public KeyValuePair <StatusCode, object> StartBattle(BattleBase battle)
        {
            try
            {
                KeyValuePair <BattleResult, BattleLog> result = _battleService.StartBattle(battle.Player1.User, battle.Player2.User);

                switch (result.Key)
                {
                case BattleResult.Player1Wins:
                {
                    int delta = CalculateEloDelta(battle.Player1.User, battle.Player2.User);
                    battle.Player1.User.Stats.Elo += delta;
                    battle.Player2.User.Stats.Elo -= delta;
                    battle.Player1.User.Stats.Logs.Add(result.Value);
                    battle.Player1.User.Stats.Wins++;
                    battle.Player2.User.Stats.Logs.Add(result.Value);
                    battle.Player2.User.Stats.Losses++;
                    break;
                }

                case BattleResult.Player2Wins:
                {
                    int delta = CalculateEloDelta(battle.Player2.User, battle.Player1.User);
                    battle.Player2.User.Stats.Elo += delta;
                    battle.Player1.User.Stats.Elo -= delta;
                    battle.Player2.User.Stats.Logs.Add(result.Value);
                    battle.Player2.User.Stats.Wins++;
                    battle.Player1.User.Stats.Logs.Add(result.Value);
                    battle.Player1.User.Stats.Losses++;
                    break;
                }

                default:
                {
                    battle.Player1.User.Stats.Logs.Add(result.Value);
                    battle.Player1.User.Stats.Draws++;
                    battle.Player2.User.Stats.Logs.Add(result.Value);
                    battle.Player2.User.Stats.Draws++;
                    break;
                }
                }

                _userController.EditStats(battle.Player1);
                _userController.EditStats(battle.Player2);
                battle.Player2.CurrentBattleLog = new KeyValuePair <StatusCode, object>(StatusCode.OK, result.Value);
                ClientMapSingleton.GetInstance.ClientMap.AddOrUpdate(battle.Player2.SessionToken, battle.Player2,
                                                                     (key, oldValue) => battle.Player2);
                return(new KeyValuePair <StatusCode, object>(StatusCode.OK, result.Value));
            }
            catch (Exception e)
            {
                battle.Player2.CurrentBattleLog = HandleException(e);
                ClientMapSingleton.GetInstance.ClientMap.AddOrUpdate(battle.Player2.SessionToken, battle.Player2,
                                                                     (key, oldValue) => battle.Player2);
                return(HandleException(e));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            Window.Title = "Test Game";
            bb           = new BattleBase(20000, 20000);

            List <int> dimensions = InitGraphicsMode(SCREEN_WIDTH, SCREEN_HEIGHT, false);

            CommandTimer.formTemplates();
            BattleGroup.setConstants(dimensions[0], dimensions[1], 10);
            UnitController.m_battleBase = bb;

            base.Initialize();
        }
Beispiel #3
0
        public ResponseContext Post(Dictionary <string, object> param)
        {
            RequestContext request       = (RequestContext)param["request"];
            MtcgClient     client        = (MtcgClient)param["client"];
            MtcgClient     waitingClient = null;

            foreach (KeyValuePair <string, MtcgClient> clientPair in ClientMapSingleton.GetInstance.ClientMap)
            {
                if (clientPair.Value.IsReadyForBattle)
                {
                    waitingClient = clientPair.Value;
                    break;
                }
            }

            if (waitingClient == null)
            {
                if (client.User.Deck.GetAllCards().Count() != 4)
                {
                    return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.BadRequest, "You have an invalid deck. Configure your deck and try again")));
                }
                client.IsReadyForBattle = true;
                ClientMapSingleton.GetInstance.ClientMap.AddOrUpdate(client.SessionToken, client,
                                                                     (key, oldValue) => client);

                while (client.IsReadyForBattle == true && client.CurrentBattleLog.Value == null)
                {
                    Thread.Sleep(100);
                    client = ClientMapSingleton.GetInstance.ClientMap[client.SessionToken];
                }

                KeyValuePair <StatusCode, object> responsePair = new KeyValuePair <StatusCode, object>(client.CurrentBattleLog.Key, client.CurrentBattleLog.Value);
                //reset battle log and ready for battle
                ResetBattleProperties(client);

                return(new ResponseContext(request, responsePair));
            }

            BattleBase battle = new BattleBase(ref client, ref waitingClient);

            if (!battle.CheckDecks())
            {
                ResetBattleProperties(client);
                return(new ResponseContext(request, new KeyValuePair <StatusCode, object>(StatusCode.BadRequest, "You have an invalid deck. Configure your deck and try again")));
            }
            ResetBattleProperties(client);
            return(new ResponseContext(request, _battleController.StartBattle(battle)));
        }
Beispiel #4
0
 // Token: 0x06003731 RID: 14129 RVA: 0x000F6D30 File Offset: 0x000F4F30
 public BattleTeam(BattleBase battle, int teamNumer)
 {
     this.m_battle     = battle;
     this.m_teamNumber = teamNumer;
     this.m_actors     = new List <BattleActor>();
     if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_ctorBattleBaseInt32_hotfix != null)
     {
         this.m_ctorBattleBaseInt32_hotfix.call(new object[]
         {
             this,
             battle,
             teamNumer
         });
         return;
     }
     BJLuaObjHelper.IsSkipLuaHotfix = false;
 }
Beispiel #5
0
        public static void TestBattleBase()
        {
            BattleBase battleBase1 = new Spear("A");
            BattleBase battleBase2 = new BattleBase("B");

            battleBase1.DeadEvent += (o, d) => Console.WriteLine($"{((BattleBase)o).Id} dead at {d}.------------");
            battleBase1.HurtEvent += (o, d) => Console.WriteLine($"{((BattleBase)o).Id} got hurt {d}.");

            battleBase2.DeadEvent += (o, d) => Console.WriteLine($"{((BattleBase)o).Id} dead at {d}.--------------");
            battleBase2.HurtEvent += (o, d) => Console.WriteLine($"{((BattleBase)o).Id} got hurt {d}.");

            Task t1 = battleBase1.AttackAsync(battleBase2);
            Task t2 = battleBase2.AttackAsync(battleBase1);

            Thread.Sleep(4000);
            battleBase1.StopAttack();
            battleBase2.StopAttack();

            Task.WhenAll(t1, t2).Wait();
        }
Beispiel #6
0
 // Token: 0x06003782 RID: 14210 RVA: 0x000F9680 File Offset: 0x000F7880
 public Combat(BattleBase battle)
 {
     this.m_battle = battle;
     this.m_teams  = new CombatTeam[2];
     for (int i = 0; i < this.m_teams.Length; i++)
     {
         this.m_teams[i] = new CombatTeam();
     }
     this.m_randomNumber = new RandomNumber();
     this.m_state        = CombatState.None;
     if (!BJLuaObjHelper.IsSkipLuaHotfix && this.TryInitHotFix("") && this.m_ctorBattleBase_hotfix != null)
     {
         this.m_ctorBattleBase_hotfix.call(new object[]
         {
             this,
             battle
         });
         return;
     }
     BJLuaObjHelper.IsSkipLuaHotfix = false;
 }
Beispiel #7
0
 public static void initialize(BattleBase bb)
 {
     m_battleBase = bb;
 }
Beispiel #8
0
 public static void initialize(BattleBase bb)
 {
     m_battleBase = bb;
 }
Beispiel #9
0
 public BattleDetailView(BattleBase battle)
     : this()
 {
     DataContext = battle;
 }
Beispiel #10
0
    private void InitPos()
    {
        float screenWidth = (transform.root as RectTransform).sizeDelta.x;

        float screenHeight = (transform.root as RectTransform).sizeDelta.y;

        float width = screenWidth / BattleConst.MAP_WIDTH;

        for (int i = 0; i < BattleConst.MAP_HEIGHT; i++)
        {
            for (int m = 0; m < BattleConst.MAP_WIDTH; m++)
            {
                int id = i * BattleConst.MAP_WIDTH + m;

                BattleCell go = Instantiate(mPosRes);

                go.gameObject.SetActive(true);

                go.SetHintVisible(false);

                float scale = width / (go.transform as RectTransform).sizeDelta.x;

                go.transform.localScale = new Vector3(scale, scale, 1);

                go.transform.SetParent(battleContainer, false);

                mPosArr[id] = go;

                (go.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + m * width, -0.5f * turrentGap - 0.5f * width - i * width + yFix);

                SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index)
                {
                    ClickMyPos(id);
                };

                SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele);
            }
        }

        mBase = Instantiate(baseRes);

        mBase.transform.SetParent(battleContainer, false);

        mBase.gameObject.SetActive(true);

        (mBase.transform as RectTransform).anchoredPosition = new Vector2(-0.5f * screenWidth + width * 0.5f + (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, -0.5f * turrentGap - 0.5f * width - BattleConst.MAP_HEIGHT * width + yFix);

        for (int i = 0; i < BattleConst.MAP_HEIGHT; i++)
        {
            for (int m = 0; m < BattleConst.MAP_WIDTH; m++)
            {
                int id = i * BattleConst.MAP_WIDTH + m;

                BattleClickGo go = Instantiate(oPosRes);

                go.gameObject.SetActive(true);

                float scale = width / (go.transform as RectTransform).sizeDelta.x;

                go.transform.localScale = new Vector3(scale, scale, 1);

                go.transform.SetParent(battleContainer, false);

                oPosArr[id] = go;

                (go.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - m * width, 0.5f * turrentGap + 0.5f * width + i * width + yFix);

                SuperFunction.SuperFunctionCallBack0 dele = delegate(int _index)
                {
                    ClickOppPos(id);
                };

                SuperFunction.Instance.AddEventListener(go.gameObject, BattleClickGo.EVENT_NAME, dele);
            }
        }

        oBase = Instantiate(baseRes);

        oBase.transform.SetParent(battleContainer, false);

        oBase.gameObject.SetActive(true);

        (oBase.transform as RectTransform).anchoredPosition = new Vector2(0.5f * screenWidth - width * 0.5f - (float)(BattleConst.MAP_WIDTH - 1) / 2 * width, 0.5f * turrentGap + 0.5f * width + BattleConst.MAP_HEIGHT * width + yFix);
    }
Beispiel #11
0
 public BattleOverview(BattleBase battle)
     : this()
 {
     DataContext = battle;
 }