Beispiel #1
0
    bool TestEncounterArmy()
    {
        for (int i = 0; i < Informations.Instance.armys.Count; i++)
        {
            ArmyInfo ai = Informations.Instance.armys[i];
            if (armyInfo == ai || king == ai.king || ai.armyCtrl.GetState() == ArmyState.Escape)
            {
                continue;
            }

            if (Vector3.Distance(transform.position, ai.armyCtrl.transform.position) < 10)
            {
                if (king == Controller.kingIndex)
                {
                    strCtrl.SetWarDialogue(armyInfo, ai);
                }
                else if (ai.king == Controller.kingIndex)
                {
                    strCtrl.SetWarDialogue(ai, armyInfo);
                }
                else
                {
                    AttackArmy(ai);
                }

                return(true);
            }
        }
        return(false);
    }
Beispiel #2
0
    public void AddArmyGeneralsList(ArmyInfo armyInfo)
    {
        mode = 1;
        gameObject.SetActive(true);

        for (int i = 0; i < armyInfo.generals.Count; i++)
        {
            int gIdx = armyInfo.generals[i];
            if (gIdx == armyInfo.commander)
            {
                generalsList.AddItem(ZhongWen.Instance.GetGeneralName1(gIdx)).SetItemData(gIdx);
                break;
            }
        }

        for (int i = 0; i < armyInfo.generals.Count; i++)
        {
            int gIdx = armyInfo.generals[i];
            if (gIdx == armyInfo.commander)
            {
                continue;
            }

            generalsList.AddItem(ZhongWen.Instance.GetGeneralName1(gIdx)).SetItemData(gIdx);
        }
    }
Beispiel #3
0
        public static void CreateMarker(SaveLua.Marker Owner, int mc)
        {
            GameObject NewMarker = Instantiate(Current.MarkerPrefab, Current.MasterChains[mc]);

            NewMarker.name = Owner.Name;
            MarkerObject NewObj = NewMarker.GetComponent <MarkerObject>();

            NewObj.Owner    = Owner;
            Owner.MarkerObj = NewObj;

            MarkerPropGraphic PropGraphic;

            if (Owner.MarkerType == SaveLua.Marker.MarkerTypes.BlankMarker && ArmyInfo.ArmyExist(Owner.Name))
            {
                PropGraphic = Current.SpawnGraphic;
            }
            else
            {
                PropGraphic = GetPropByType(Owner.MarkerType);
            }
            NewObj.Mf.sharedMesh     = PropGraphic.SharedMesh;
            NewObj.Mr.sharedMaterial = PropGraphic.SharedMaterial;
            NewObj.Bc.size           = PropGraphic.SharedMesh.bounds.size;
            NewObj.Bc.center         = PropGraphic.SharedMesh.bounds.center;

            NewObj.Tr.localPosition = ScmapEditor.ScmapPosToWorld(Owner.position);
            NewObj.Tr.localRotation = MarkerObject.ScmapRotToMarkerRot(Owner.orientation, Owner.MarkerType);

            NewMarker.SetActive(Current.MarkerLayersSettings.ActiveByType(Owner.MarkerType));
        }
Beispiel #4
0
 public void PopulateFields(ArmyInfo data)
 {
     this.gameObject.SetActive(true);
     lblGeneral.WriteLabel(data.General);
     lblStrength.WriteLabel(data.Strength);
     lblCavalry.WriteLabel(data.Knights);
     lblArchers.WriteLabel(data.Archers);
     lblInfantry.WriteLabel(data.Spearmen);
 }
Beispiel #5
0
    public void InitArmyInfo(ArmyInfo ai)
    {
        armyInfo          = ai;
        armyInfo.armyCtrl = GetComponent <ArmyController>();

        SetArmyKingFlag();

        if (armyInfo.cityTo != -1)
        {
            if (pathfinding == null)
            {
                pathfinding = GameObject.FindWithTag("Pathfinding").GetComponent <MyPathfinding>();
            }
            SetRoute(pathfinding.GetRoute(armyInfo.pos, armyInfo.cityTo));
        }

        state    = (ArmyState)armyInfo.state;
        timeTick = armyInfo.timeTick;

        if (state == ArmyState.Garrison)
        {
            exSprite          moveSprite = GetComponent <exSprite>();
            exSpriteAnimation moveAnim   = GetComponent <exSpriteAnimation>();
            moveAnim.Stop();

            int frame = armyInfo.direction;
            if (frame == -1)
            {
                frame = 0;
            }
            moveAnim.SetFrame("ArmyGarrison", frame);

            Vector3 pos = flagPos[3 + frame];
            if (!armyInfo.isFlipped)
            {
                pos.x = -pos.x;
            }
            else
            {
                isHFlipped = true;
                moveSprite.HFlip();

                exSprite    flagSprite = flagCtrl.GetComponent <exSprite>();
                BoxCollider flagCol    = flagCtrl.GetComponent <BoxCollider>();
                flagSprite.HFlip();
                flagCol.center = new Vector3(-flagCol.center.x, flagCol.center.y, flagCol.center.z);
            }

            flagCtrl.localPosition = pos;
        }
        else
        {
            CalcDirection();
        }
    }
Beispiel #6
0
    public void AddArmyPrisonsList(ArmyInfo armyInfo)
    {
        mode = 1;
        gameObject.SetActive(true);

        for (int i = 0; i < armyInfo.prisons.Count; i++)
        {
            int gIdx = armyInfo.prisons[i];
            generalsList.AddItem(ZhongWen.Instance.GetGeneralName1(gIdx)).SetItemData(gIdx);
        }
    }
Beispiel #7
0
        public PlayerActionResult Execute()
        {
            if (!CheckMP())
            {
                return(new PlayerActionResult(false, ResultType.NoMovement));
            }

            Kingdom            kingdom  = Action.player.CurrentKingdom;
            ArmyInfo           armyinfo = new ArmyInfo(Action.player.CurrentKingdom.Army);
            PlayerActionResult result   = new PlayerActionResult(true, ResultType.Success, army1: armyinfo);

            return(result);
        }
Beispiel #8
0
    void ArmyAct(int i)
    {
        ArmyInfo armyInfo = Informations.Instance.armys[i];

        if (armyInfo.king != Controller.kingIndex && armyInfo.armyCtrl.GetState() == ArmyController.ArmyState.Garrison)
        {
            int cityCanIntoIdx = pathfinding.GetCityIndex(armyInfo.armyCtrl.transform.position, 30);
            if (cityCanIntoIdx != -1)
            {
                armyInfo.armyCtrl.IntoTheCity(cityCanIntoIdx);
            }
        }
    }
Beispiel #9
0
    public void SetArmyInfo(ArmyInfo a)
    {
        armyInfo = a;

        gameObject.SetActive(true);

        infoCtrl.SetArmy(armyInfo);

        if (armyInfo.king == Controller.kingIndex)
        {
            for (int i = 0; i < commands.Length; i++)
            {
                commands[i].SetButtonEnable(true);
            }

            if (armyInfo.prisons.Count > 0)
            {
                commands[3].SetButtonEnable(true);
            }
            else
            {
                commands[3].SetButtonEnable(false);
            }

            Vector3 pos = armyInfo.armyCtrl.transform.position;
            cityCanIntoIdx = path.GetCityIndex(pos, 30);
            if (cityCanIntoIdx != -1)
            {
                if (Informations.Instance.GetCityInfo(cityCanIntoIdx).king == armyInfo.king)
                {
                    commands[4].SetButtonEnable(true);
                }
                else
                {
                    commands[4].SetButtonEnable(false);
                }
            }
            else
            {
                commands[4].SetButtonEnable(false);
            }
        }
        else
        {
            for (int i = 0; i < commands.Length; i++)
            {
                commands[i].SetButtonEnable(false);
            }
        }
    }
Beispiel #10
0
    void SetArmy(ArmyInfo armyInfo)
    {
        if (armyInfo.pos == Vector3.zero)
        {
            armyInfo.pos = pathfinding.GetCityPos(armyInfo.cityFrom);
        }

        GameObject go = (GameObject)Instantiate(armyPrefab, armyInfo.pos, transform.rotation);

        go.transform.parent = root.transform;
        ArmyController armyCtrl = go.GetComponent <ArmyController>();

        armyCtrl.InitArmyInfo(armyInfo);
    }
Beispiel #11
0
    public void SetArmy(ArmyInfo armyInfo)
    {
        head.SetGeneralHead(armyInfo.commander);

        if (armyInfo.king < Informations.Instance.kingNum)
        {
            kingName.text = ZhongWen.Instance.GetKingName(armyInfo.king) + ZhongWen.Instance.jun;
        }
        else
        {
            kingName.text = ZhongWen.Instance.daozei + ZhongWen.Instance.jun;
        }

        string cName = ZhongWen.Instance.GetGeneralName(armyInfo.commander);

        commanderName.text = cName;

        if (armyInfo.cityTo != -1)
        {
            targetcity.text = ZhongWen.Instance.GetCityName(armyInfo.cityTo);
        }
        else
        {
            targetcity.text = "---";
        }

        generalNum.text = armyInfo.generals.Count + "";

        if (armyInfo.king == Controller.kingIndex)
        {
            int sNum = 0;
            for (int i = 0; i < armyInfo.generals.Count; i++)
            {
                sNum += Informations.Instance.GetGeneralInfo(armyInfo.generals[i]).soldierCur;
                sNum += Informations.Instance.GetGeneralInfo(armyInfo.generals[i]).knightCur;
            }
            soldierNum.text = sNum + "";

            prisonNum.text = armyInfo.prisons.Count + "";
            money.text     = armyInfo.money + "";
        }
        else
        {
            soldierNum.text = "---";
            prisonNum.text  = "---";
            money.text      = "---";
        }
    }
Beispiel #12
0
 public Informations()
 {
     armys    = new List <ArmyInfo>();
     mine     = new ArmyInfo();
     captures = new DMap <int, StatCapture>();
     dungeons = new Dictionary <int, StatDungeon>();
     statVip  = new StatVip();
     statSign = new StatSign();
     statRole = new StatRole();
     statRole.RandomGenerate();
     statChat                  = new StatChat();
     statDugeonChapterMap      = new StatDugeonChapterMap();
     statDugeonChapterMapElite = new StatDugeonChapterMap();
     InitArmy();
     InitDefaultGeneralsInfo();
 }
Beispiel #13
0
    void SetKingOver(int kIdx)
    {
        for (int g = 0; g < Informations.Instance.generalNum; g++)
        {
            GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(g);

            if (gInfo.king == kIdx)
            {
                gInfo.king = Informations.Instance.kingNum;
            }
        }

        for (int c = 0; c < Informations.Instance.cityNum; c++)
        {
            CityInfo cInfo = Informations.Instance.GetCityInfo(c);

            if (cInfo.king == kIdx)
            {
                cInfo.king = Informations.Instance.kingNum;
                for (int i = 0; i < cInfo.prisons.Count; i++)
                {
                    Informations.Instance.GetGeneralInfo(cInfo.prisons[i]).prisonerIdx = Informations.Instance.kingNum;
                }
            }
        }

        for (int i = 0; i < Informations.Instance.armys.Count; i++)
        {
            ArmyInfo ai = Informations.Instance.armys[i];

            if (ai.king == kIdx)
            {
                ai.king = Informations.Instance.kingNum;
            }
            for (int j = 0; j < ai.prisons.Count; j++)
            {
                Informations.Instance.GetGeneralInfo(ai.prisons[j]).prisonerIdx = Informations.Instance.kingNum;
            }
        }

        KingInfo kInfo = Informations.Instance.GetKingInfo(kIdx);

        kInfo.generals.Clear();
        kInfo.cities.Clear();
        kInfo.active = 0;
    }
Beispiel #14
0
        public static MarkerPropGraphic GetPropByType(MapLua.SaveLua.Marker.MarkerTypes mType)
        {
            if (mType == MapLua.SaveLua.Marker.MarkerTypes.BlankMarker && ArmyInfo.ArmyExist(mType.ToString()))
            {
                return(Current.SpawnGraphic);
            }

            for (int i = 0; i < Current.MarkerPropGraphics.Length; i++)
            {
                if (Current.MarkerPropGraphics[i].mType == mType)
                {
                    return(Current.MarkerPropGraphics[i]);
                }
            }

            return(Current.MarkerPropGraphics[0]);
        }
Beispiel #15
0
    void CheckCorrection()
    {
        for (int i = 0; i < Informations.Instance.cityNum; i++)
        {
            CityInfo cInfo = Informations.Instance.GetCityInfo(i);

            if (cInfo.generals.Count <= 10)
            {
                continue;
            }

            do
            {
                ArmyInfo ai = new ArmyInfo();
                ai.king  = cInfo.king;
                ai.state = (int)ArmyController.ArmyState.Garrison;

                if (pathfinding == null)
                {
                    pathfinding = GameObject.FindWithTag("Pathfinding").GetComponent <MyPathfinding>();
                }
                ai.pos = pathfinding.GetCityPos(i);

                Informations.Instance.armys.Add(ai);

                int count = cInfo.generals.Count;
                int min   = count - 5;
                min = Mathf.Clamp(min, 10, count);
                for (int j = count - 1; j >= min; j--)
                {
                    int g = cInfo.generals[j];
                    ai.generals.Add(g);
                    cInfo.generals.RemoveAt(j);

                    Informations.Instance.GetGeneralInfo(g).city = -1;

                    if (cInfo.prefect == g)
                    {
                        cInfo.prefect = FindCommander(cInfo.generals, cInfo.king);
                    }
                }

                ai.commander = FindCommander(ai.generals, ai.king);
            } while(cInfo.generals.Count > 10);
        }
    }
    public void AddArmyTarget(ArmyInfo armyInfo)
    {
        string generalName = ZhongWen.Instance.GetGeneralName1(armyInfo.commander);

        if (generalName.Length == 4 && generalName[1] != ' ' && generalName[2] != ' ')
        {
            generalName = generalName + ZhongWen.Instance.budui;
        }
        else
        {
            generalName = generalName + "  " + ZhongWen.Instance.budui;
        }

        TargetData data = new TargetData(1, armyInfo);
        ListItem   item = targetList.AddItem(generalName);

        item.SetItemData(data);
    }
Beispiel #17
0
    void AttackArmy(ArmyInfo enemy)
    {
        int result   = 0;
        int selfIdx  = 0;
        int enemyIdx = 0;

        while (result == 0)
        {
            GeneralInfo selfGeneral  = Informations.Instance.GetGeneralInfo(armyInfo.generals[selfIdx]);
            GeneralInfo enemyGeneral = Informations.Instance.GetGeneralInfo(enemy.generals[enemyIdx]);

            int power1 = selfGeneral.level * 5 + selfGeneral.knightCur * 6 + selfGeneral.soldierCur * 3 + selfGeneral.strength * 2 + selfGeneral.healthCur + selfGeneral.manaCur / 2 + Random.Range(0, 20);
            int power2 = enemyGeneral.level * 5 + enemyGeneral.knightCur * 6 + enemyGeneral.soldierCur * 3 + enemyGeneral.strength * 2 + enemyGeneral.healthCur + enemyGeneral.manaCur / 2 + Random.Range(0, 20);

            if (power1 > power2)
            {
                WarResult(selfGeneral, enemyGeneral, power2);
                enemyIdx++;
            }
            else
            {
                WarResult(enemyGeneral, selfGeneral, power1);
                selfIdx++;
            }

            if (selfIdx >= armyInfo.generals.Count)
            {
                result = 2;
            }
            else if (enemyIdx >= enemy.generals.Count)
            {
                result = 1;
            }
        }

        if (result == 1)
        {
            WarResult(armyInfo, enemy);
        }
        else if (result == 2)
        {
            WarResult(enemy, armyInfo);
        }
    }
Beispiel #18
0
    void SetKingOver(int kIdx)
    {
        for (int g = 0; g < Informations.Instance.generalNum; g++)
        {
            GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(g);

            if (gInfo.king == kIdx)
            {
                gInfo.king = Informations.Instance.kingNum;
            }
        }

        for (int c = 0; c < Informations.Instance.cityNum; c++)
        {
            CityInfo cInfo = Informations.Instance.GetCityInfo(c);

            if (cInfo.king == kIdx)
            {
                cInfo.king = Informations.Instance.kingNum;
                cityFlagsCtrl.SetFlag(c);
            }
        }

        for (int i = 0; i < Informations.Instance.armys.Count; i++)
        {
            ArmyInfo ai = Informations.Instance.armys[i];

            if (ai.king == kIdx)
            {
                ai.king = Informations.Instance.kingNum;
                ai.armyCtrl.SetArmyKingFlag();
            }
        }

        KingInfo kInfo = Informations.Instance.GetKingInfo(kIdx);

        kInfo.generals.Clear();
        kInfo.cities.Clear();
        kInfo.active = 0;
    }
Beispiel #19
0
    void FindArmyCommander(ArmyInfo armyInfo)
    {
        int strengthMax = 0;
        int commander   = -1;

        for (int i = 0; i < armyInfo.generals.Count; i++)
        {
            if (armyInfo.commander == armyInfo.generals[i] || Informations.Instance.GetKingInfo(armyInfo.king).generalIdx == armyInfo.generals[i])
            {
                commander = armyInfo.generals[i];
                break;
            }

            int strengthCur = Informations.Instance.GetGeneralInfo(armyInfo.generals[i]).strength;
            if (strengthCur > strengthMax)
            {
                commander   = armyInfo.generals[i];
                strengthMax = strengthCur;
            }
        }

        armyInfo.commander = commander;
    }
Beispiel #20
0
        public static void UpdateGraphics(SaveLua.Marker Owner, int mc)
        {
            bool Active = true;
            MarkerPropGraphic PropGraphic;

            if (Owner.MarkerType == SaveLua.Marker.MarkerTypes.BlankMarker && ArmyInfo.ArmyExist(Owner.Name))
            {
                PropGraphic = Current.SpawnGraphic;
                Active      = Current.MarkerLayersSettings.Spawn;
            }
            else
            {
                PropGraphic = GetPropByType(Owner.MarkerType);
                Active      = Current.MarkerLayersSettings.ActiveByType(Owner.MarkerType);
            }

            Owner.MarkerObj.Mf.sharedMesh     = PropGraphic.SharedMesh;
            Owner.MarkerObj.Mr.sharedMaterial = PropGraphic.SharedMaterial;
            Owner.MarkerObj.Bc.size           = PropGraphic.SharedMesh.bounds.size;
            Owner.MarkerObj.Bc.center         = PropGraphic.SharedMesh.bounds.center;

            Owner.MarkerObj.gameObject.SetActive(Active);
        }
Beispiel #21
0
    public void SetWarDialogue(ArmyInfo army, int cityAttacked)
    {
        state = State.OnWar;

        Vector3 pos = army.armyCtrl.transform.position;

        pos.x          = Mathf.Clamp(pos.x, -320, 320);
        pos.y          = Mathf.Clamp(pos.y, -240, 240);
        strategyCamPos = pos;

        hTimeCtrl.SetAnim(MenuDisplayAnim.AnimType.OutToLeft);
        flagsCtrl.SetFlagsAnimPause();
        SetArmyPause();

        string msg = ZhongWen.Instance.wojun + ZhongWen.Instance.GetGeneralName(army.commander) + ZhongWen.Instance.budui
                     + ZhongWen.Instance.gongji + ZhongWen.Instance.GetCityName(cityAttacked) + ZhongWen.Instance.chengTarget + ZhongWen.Instance.tanhao;

        dialog.SetDialogue(Informations.Instance.GetKingInfo(Controller.kingIndex).generalIdx, msg, MenuDisplayAnim.AnimType.InsertFromBottom);

        SelectGeneralToWarController.isWarBegin   = true;
        SelectGeneralToWarController.mode         = 2;
        SelectGeneralToWarController.cityAttacked = cityAttacked;
        SelectGeneralToWarController.mine         = army;
    }
Beispiel #22
0
    public void SetWarDialogue(ArmyInfo mine, ArmyInfo enemy)
    {
        state = State.OnWar;

        Vector3 pos = mine.armyCtrl.transform.position;

        pos.x          = Mathf.Clamp(pos.x, -320, 320);
        pos.y          = Mathf.Clamp(pos.y, -240, 240);
        strategyCamPos = pos;

        hTimeCtrl.SetAnim(MenuDisplayAnim.AnimType.OutToLeft);
        flagsCtrl.SetFlagsAnimPause();
        SetArmyPause();

        string msg = ZhongWen.Instance.wojun + ZhongWen.Instance.GetGeneralName(mine.commander) + ZhongWen.Instance.budui
                     + ZhongWen.Instance.zaoyu + ZhongWen.Instance.GetGeneralName(enemy.commander) + ZhongWen.Instance.jun + ZhongWen.Instance.fashengzhandou;

        dialog.SetDialogue(Informations.Instance.GetKingInfo(Controller.kingIndex).generalIdx, msg, MenuDisplayAnim.AnimType.InsertFromBottom);

        SelectGeneralToWarController.isWarBegin = true;
        SelectGeneralToWarController.mode       = 0;
        SelectGeneralToWarController.mine       = mine;
        SelectGeneralToWarController.enemy      = enemy;
    }
Beispiel #23
0
        public static void UpdateLayers()
        {
            for (int mc = 0; mc < MapLuaParser.Current.SaveLuaFile.Data.MasterChains.Length; mc++)
            {
                int Mcount = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count;
                for (int m = 0; m < Mcount; m++)
                {
                    if (MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj != null)
                    {
                        bool Active = true;

                        if (MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerType == SaveLua.Marker.MarkerTypes.BlankMarker &&
                            ArmyInfo.ArmyExist(MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].Name))
                        {
                            Active = Current.MarkerLayersSettings.Spawn;
                        }
                        else
                        {
                            Active = Current.MarkerLayersSettings.ActiveByType(MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerType);
                        }


                        if (Active && !MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.gameObject.activeSelf)
                        {
                            MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.gameObject.SetActive(true);
                        }
                        else if (!Active && MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.gameObject.activeSelf)
                        {
                            MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[m].MarkerObj.gameObject.SetActive(false);
                        }
                    }
                }
            }

            RenderMarkersConnections.Current.UpdateConnections();
        }
Beispiel #24
0
    void SetEscapeFromCity(int cIdx)
    {
        CityInfo cInfo = Informations.Instance.GetCityInfo(cIdx);

        do
        {
            ArmyInfo ai = new ArmyInfo();
            ai.king  = cInfo.king;
            ai.money = 0;

            Informations.Instance.armys.Add(ai);

            int count = cInfo.generals.Count;
            int min   = count - 5;
            min = Mathf.Clamp(min, 0, count);
            for (int i = count - 1; i >= min; i--)
            {
                int g = cInfo.generals[i];
                ai.generals.Add(g);
                cInfo.generals.RemoveAt(i);

                Informations.Instance.GetGeneralInfo(g).city = -1;
            }

            ai.commander = -1;
            FindArmyCommander(ai);

            int        cityEscTo = -1;
            List <int> clist     = MyPathfinding.GetCityNearbyIdx(cIdx);
            List <int> canGoList = new List <int>();

            if (clist.Count == 1)
            {
                cityEscTo = clist[0];
            }
            else
            {
                for (int i = 0; i < clist.Count; i++)
                {
                    if (Informations.Instance.GetCityInfo(clist[i]).king == ai.king)
                    {
                        canGoList.Add(clist[i]);
                    }
                }

                if (canGoList.Count > 0)
                {
                    cityEscTo = canGoList[Random.Range(0, canGoList.Count)];
                }

                if (cityEscTo == -1)
                {
                    for (int i = 0; i < clist.Count; i++)
                    {
                        if (Informations.Instance.GetCityInfo(clist[i]).king == -1)
                        {
                            canGoList.Add(clist[i]);
                        }
                    }

                    if (canGoList.Count > 0)
                    {
                        cityEscTo = canGoList[Random.Range(0, canGoList.Count)];
                    }
                }

                if (cityEscTo == -1)
                {
                    cityEscTo = clist[Random.Range(0, clist.Count)];
                }
            }

            ai.cityFrom = cityAttacked;
            ai.cityTo   = cityEscTo;

            ai.state = (int)ArmyController.ArmyState.Escape;
            ai.pos   = Vector3.zero;
        } while(cInfo.generals.Count > 0);
    }
Beispiel #25
0
 public Informations()
 {
     armys = new List<ArmyInfo>();
     mine = new ArmyInfo();
     captures = new DMap<int, StatCapture>();
     dungeons = new Dictionary<int, StatDungeon>();
     statVip = new StatVip();
     statSign = new StatSign();
     statRole = new StatRole();
     statRole.RandomGenerate();
     statChat = new StatChat();
     statDugeonChapterMap = new StatDugeonChapterMap();
     statDugeonChapterMapElite = new StatDugeonChapterMap();
     InitArmy();
     InitDefaultGeneralsInfo();
 }
Beispiel #26
0
    IEnumerator GenerateingList()
    {
        //Debug.Log("Regenerate");
        int mc = 0;
        //const int PauseEvery = 64;
        //int GenerateCounter = 0;

        int Mcount     = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers.Count;
        int TypesCount = (int)MapLua.SaveLua.Marker.MarkerTypes.Count;

        MapLua.SaveLua.Marker CurrentMarker;
        GameObject            newList;
        ListObject            NewListObject;
        int t = 0;
        int i = 0;

        float Realtime = Time.realtimeSinceStartup;
        //const float MaxAllowedOverhead = 0.03334f;
        const float MaxAllowedOverhead = 0.3f;


        List <GameObject> AllObjectsList = new List <GameObject>(1024);

        for (t = 0; t < TypesCount; t++)
        {
            List <GameObject> ObjectToSort = new List <GameObject>(1024);

            for (i = 0; i < Mcount; i++)
            {
                CurrentMarker = MapLuaParser.Current.SaveLuaFile.Data.MasterChains[mc].Markers[i];
                if ((int)CurrentMarker.MarkerType != t)
                {
                    continue;
                }

                if (CurrentMarker == null || CurrentMarker.MarkerObj == null)
                {
                    continue;
                }

                newList = Instantiate(ListPrefab, Pivot.position, Quaternion.identity) as GameObject;
                newList.GetComponent <RectTransform>().SetParent(Pivot);
                newList.name = CurrentMarker.Name;
                ObjectToSort.Add(newList);

                NewListObject = newList.GetComponent <ListObject>();
                AllFields.Add(NewListObject);
                NewListObject.ObjectName.text     = CurrentMarker.Name;
                NewListObject.InstanceId          = i;
                NewListObject.ListId              = 0;
                NewListObject.ConnectedGameObject = CurrentMarker.MarkerObj.gameObject;
                NewListObject.ClickAction         = SelectListGameobject;

                if (!NewListObject.ConnectedGameObject.activeSelf)
                {
                    newList.SetActive(false);
                }

                if (Selection.SelectionManager.Current.Selection.Ids.Contains(i))
                {
                    NewListObject.SetSelection(1);
                }
                else
                {
                    NewListObject.SetSelection(0);

                    if (Selection.SelectionManager.Current.SymetrySelection.Length > 0)
                    {
                        for (int s = 0; s < Selection.SelectionManager.Current.SymetrySelection.Length; s++)
                        {
                            if (Selection.SelectionManager.Current.SymetrySelection[s].Ids.Contains(i))
                            {
                                NewListObject.SetSelection(2);
                            }
                        }
                    }
                }
                if (CurrentMarker.MarkerType == MapLua.SaveLua.Marker.MarkerTypes.BlankMarker && ArmyInfo.ArmyExist(CurrentMarker.Name))
                {
                    NewListObject.Icon.sprite = Markers.MarkersControler.Current.SpawnGraphic.Icon;
                }
                else
                {
                    NewListObject.Icon.sprite = Markers.MarkersControler.GetIconByType(CurrentMarker.MarkerType);
                }

                /*GenerateCounter++;
                 * if (GenerateCounter > PauseEvery)
                 * {
                 *      GenerateCounter = 0;
                 *      yield return null;
                 *
                 * }*/
                if (Time.realtimeSinceStartup - Realtime > MaxAllowedOverhead)
                {
                    yield return(null);

                    Realtime = Time.realtimeSinceStartup;
                }
            }

            AllObjectsList.AddRange(ObjectToSort.OrderBy(go => go.name));
        }

        int ListCount = AllObjectsList.Count;

        for (i = 0; i < ListCount; i++)
        {
            AllObjectsList[i].transform.SetSiblingIndex(i);
        }

        Generated      = true;
        GeneratedCount = AllFields.Count;


        Layout.enabled     = true;
        SizeFitter.enabled = true;

        yield return(null);

        Layout.enabled     = false;
        SizeFitter.enabled = false;
        GeneratingEnum     = null;
        if (Buffor)
        {
            Buffor = false;
            UpdateSelectionAfterGenerate = false;
            GenerateList();
        }
        else if (UpdateSelectionAfterGenerate)
        {
            UpdateSelectionAfterGenerate = false;
            UpdateSelection();
        }
    }
Beispiel #27
0
    void WarOverResultArmyToCity(ArmyInfo armyInfo, int cIdx, bool isWin)
    {
        CityInfo cInfo = Informations.Instance.GetCityInfo(cIdx);

        if (isWin)
        {
            for (int i = 0; i < armyInfo.generals.Count; i++)
            {
                GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(armyInfo.generals[i]);
                gInfo.prisonerIdx = -1;
                gInfo.city        = cIdx;
                gInfo.escape      = 0;

                if (gInfo.level > 4)
                {
                    //gInfo.experience += 137 * (gInfo.level - 4) / 2;
                    gInfo.experience += (Misc.GetLevelExperience(gInfo.level + 1) - Misc.GetLevelExperience(gInfo.level)) / 2;
                }
                else
                {
                    gInfo.experience += 50;
                }
                CheckLevelUp(gInfo);
            }

            int count = cInfo.generals.Count;
            for (int i = count - 1; i >= 0; i--)
            {
                if (Informations.Instance.GetGeneralInfo(cInfo.generals[i]).prisonerIdx == armyInfo.king)
                {
                    cInfo.prisons.Add(cInfo.generals[i]);
                    Informations.Instance.GetKingInfo(cInfo.king).generals.Remove(cInfo.generals[i]);

                    if (cInfo.generals[i] == Informations.Instance.GetKingInfo(cInfo.king).generalIdx)
                    {
                        SetKingOver(cInfo.king);
                    }

                    cInfo.generals.RemoveAt(i);
                }
            }

            count = cInfo.generals.Count;
            if (count > 0)
            {
                SetEscapeFromCity(cIdx);
            }

            //cInfo.generals.Clear();
            cInfo.generals.AddRange(armyInfo.generals);
            cInfo.prefect = armyInfo.commander;

            for (int i = 0; i < cInfo.prisons.Count; i++)
            {
                Informations.Instance.GetGeneralInfo(cInfo.prisons[i]).prisonerIdx = armyInfo.king;
            }

            for (int i = 0; i < armyInfo.prisons.Count; i++)
            {
                Informations.Instance.GetGeneralInfo(armyInfo.prisons[i]).city = cIdx;
            }

            cInfo.prisons.AddRange(armyInfo.prisons);
            cInfo.money += armyInfo.money;

            Informations.Instance.armys.Remove(armyInfo);

            if (cInfo.king != -1)
            {
                KingInfo kInfo = Informations.Instance.GetKingInfo(cInfo.king);
                kInfo.cities.Remove(cIdx);
            }

            cInfo.king = armyInfo.king;
            Informations.Instance.GetKingInfo(cInfo.king).cities.Add(cIdx);
        }
        else
        {
            for (int i = 0; i < cInfo.generals.Count; i++)
            {
                GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(cInfo.generals[i]);
                gInfo.prisonerIdx = -1;

                if (gInfo.level > 4)
                {
                    //gInfo.experience += 137 * (gInfo.level - 4) / 2;
                    gInfo.experience += (Misc.GetLevelExperience(gInfo.level + 1) - Misc.GetLevelExperience(gInfo.level)) / 2;
                }
                else
                {
                    gInfo.experience += 50;
                }
                CheckLevelUp(gInfo);
            }

            int count = armyInfo.generals.Count;
            for (int i = count - 1; i >= 0; i--)
            {
                int gIdx = armyInfo.generals[i];
                if (Informations.Instance.GetGeneralInfo(gIdx).prisonerIdx == cInfo.king)
                {
                    if (gIdx == Informations.Instance.GetKingInfo(armyInfo.king).generalIdx)
                    {
                        SetKingOver(armyInfo.king);
                    }

                    cInfo.prisons.Add(gIdx);
                    Informations.Instance.GetGeneralInfo(gIdx).city = cIdx;

                    Informations.Instance.GetKingInfo(armyInfo.king).generals.Remove(gIdx);
                    armyInfo.generals.RemoveAt(i);
                }
            }

            if (armyInfo.generals.Count == 0)
            {
                for (int i = 0; i < armyInfo.prisons.Count; i++)
                {
                    Informations.Instance.GetGeneralInfo(armyInfo.prisons[i]).prisonerIdx = cInfo.king;
                    Informations.Instance.GetGeneralInfo(armyInfo.prisons[i]).city        = cIdx;
                }

                cInfo.prisons.AddRange(armyInfo.prisons);
                armyInfo.prisons.Clear();

                cInfo.money += armyInfo.money;
                Informations.Instance.armys.Remove(armyInfo);
            }
            else
            {
                FindArmyCommander(armyInfo);

                armyInfo.cityTo   = armyInfo.cityFrom;
                armyInfo.cityFrom = cIdx;

                armyInfo.state = (int)ArmyController.ArmyState.Escape;
            }
        }
    }
Beispiel #28
0
    void SetArmyMove(int fo, int to, int num)
    {
        CityInfo cInfo = Informations.Instance.GetCityInfo(fo);

        ArmyInfo armyInfo = new ArmyInfo();

        armyInfo.king     = cInfo.king;
        armyInfo.cityFrom = fo;
        armyInfo.cityTo   = to;
        armyInfo.money    = Random.Range(0, cInfo.money);
        armyInfo.pos      = pathfinding.GetCityPos(fo);

        bool isPerfect = false;
        int  count     = cInfo.generals.Count;

        int numLeft = num;
        int j       = count - 1;

        while (numLeft > 0 && j >= 0)
        {
            GeneralInfo gInfo = Informations.Instance.GetGeneralInfo(cInfo.generals[j]);
            if (gInfo.healthCur > 50)
            {
                if (cInfo.generals[j] == cInfo.prefect)
                {
                    if (Random.Range(0, 100) > 50)
                    {
                        isPerfect          = true;
                        armyInfo.commander = cInfo.generals[j];
                    }
                    else
                    {
                        j--;
                        continue;
                    }
                }

                gInfo.city = -1;
                armyInfo.generals.Add(cInfo.generals[j]);
                cInfo.generals.RemoveAt(j);

                numLeft--;
            }
            j--;
        }

        if (armyInfo.generals.Count == 0)
        {
            return;
        }

        if (cInfo.prisons.Count > 0 && Random.Range(0, 100) > 60)
        {
            for (int i = 0; i < cInfo.prisons.Count; i++)
            {
                Informations.Instance.GetGeneralInfo(cInfo.prisons[i]).city = -1;
            }
            armyInfo.prisons.AddRange(cInfo.prisons);
            cInfo.prisons.Clear();
        }

        if (isPerfect)
        {
            cInfo.prefect = cInfo.generals[0];
            for (int k = 0; k < cInfo.generals.Count; k++)
            {
                if (cInfo.generals[k] == Informations.Instance.GetKingInfo(cInfo.king).generalIdx)
                {
                    cInfo.prefect = cInfo.generals[k];
                    break;
                }

                if (Informations.Instance.GetGeneralInfo(cInfo.prefect).strength
                    < Informations.Instance.GetGeneralInfo(cInfo.generals[k]).strength)
                {
                    cInfo.prefect = cInfo.generals[k];
                }
            }
        }
        else
        {
            armyInfo.commander = armyInfo.generals[0];
            for (int k = 0; k < armyInfo.generals.Count; k++)
            {
                if (armyInfo.generals[k] == Informations.Instance.GetKingInfo(armyInfo.king).generalIdx)
                {
                    armyInfo.commander = armyInfo.generals[k];
                    break;
                }

                if (Informations.Instance.GetGeneralInfo(armyInfo.commander).strength
                    < Informations.Instance.GetGeneralInfo(armyInfo.generals[k]).strength)
                {
                    armyInfo.commander = armyInfo.generals[k];
                }
            }
        }

        SetArmy(armyInfo);
        Informations.Instance.armys.Add(armyInfo);
    }
Beispiel #29
0
    void RemoveGeneralFromCityAndArmy()
    {
        if (generalInfo.city == -1)
        {
            for (int i = 0; i < Informations.Instance.armys.Count; i++)
            {
                ArmyInfo army = Informations.Instance.armys[i];

                if (army.generals.Contains(generalIndex))
                {
                    army.generals.Remove(generalIndex);
                    if (army.generals.Count == 0)
                    {
                        for (int j = 0; j < army.prisons.Count; j++)
                        {
                            Informations.Instance.GetGeneralInfo(army.prisons[i]).king = -1;
                        }
                        Informations.Instance.armys.Remove(army);
                    }
                    else
                    {
                        if (army.commander == generalIndex)
                        {
                            army.commander = army.generals[0];
                        }
                    }
                    break;
                }

                if (army.prisons.Contains(generalIndex))
                {
                    generalInfo.prisonerIdx = -1;
                    army.prisons.Remove(generalIndex);
                    break;
                }
            }
        }
        else
        {
            CityInfo cInfo = Informations.Instance.GetCityInfo(generalInfo.city);
            if (cInfo.generals.Contains(generalIndex))
            {
                cInfo.generals.Remove(generalIndex);
                if (cInfo.generals.Count == 0)
                {
                    if (cInfo.king != -1)
                    {
                        Informations.Instance.GetKingInfo(cInfo.king).cities.Remove(generalInfo.city);
                        cInfo.king = -1;
                    }
                    for (int i = 0; i < cInfo.prisons.Count; i++)
                    {
                        Informations.Instance.GetGeneralInfo(cInfo.prisons[i]).king = -1;
                        Informations.Instance.GetGeneralInfo(cInfo.prisons[i]).city = -1;
                    }
                }
                else
                {
                    if (cInfo.prefect == generalIndex)
                    {
                        cInfo.prefect = cInfo.generals[0];
                    }
                }
            }
            else if (cInfo.prisons.Contains(generalIndex))
            {
                generalInfo.prisonerIdx = -1;
                cInfo.prisons.Remove(generalIndex);
            }
        }
    }
Beispiel #30
0
 public void UpdateArmyInfo(ArmyInfo armyInfo)
 {
     Deselect();
     armyUpdater.SetActive(true);
     armyUpdater.GetComponent <ArmyInfoUpdater>().PopulateFields(armyInfo);
 }
Beispiel #31
0
        public void GetPlayerBattleUnitByType(BattleType type, List <BattleUnit> battleUnits)
        {
            int      armyIndex = GetArmyIndexByBattleType(type);
            ArmyInfo army      = player.battleArmyList.ArmyList.Find(p => p.listId == (armyIndex));

            Dictionary <int, float[]> runeDic = GetRunePageAttribute((GetRuneIndexByBattleType(type)));

            for (int i = 0; i < army.unitIds.Count; i++)
            {
                BattleUnit unit = battleUnits.Find(p => p.metaId == army.unitIds[i]);

                SoldierInfo s = player.army.soldiers.Find(p => p.metaId == army.unitIds[i]);

                UnitsProto.Unit soldierProto = unitsProtoData.Find(p => p.ID == s.metaId);

                unit        = new BattleUnit();
                unit.metaId = army.unitIds[i];
                unit.count  = 1;

                foreach (KeyValuePair <int, float[]> item in runeDic)
                {
                    PropertyInfo temp = new PropertyInfo();
                    temp.propertyType = ( PropertyType )item.Key;

                    if (temp.propertyType == PropertyType.ArmorPro)
                    {
                        temp.propertyValue = soldierProto.Armor * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.AttackRange)
                    {
                        temp.propertyValue = soldierProto.AttackRange * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.AttackSpeed)
                    {
                        temp.propertyValue = soldierProto.AttackInterval * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.CriticalChance)
                    {
                        temp.propertyValue = soldierProto.CriticalChance * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.CriticalDamage)
                    {
                        temp.propertyValue = soldierProto.CriticalDamage * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.HealthRecover)
                    {
                        temp.propertyValue = soldierProto.HealthRegen * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.MagicAttack)
                    {
                        temp.propertyValue = soldierProto.MagicAttack * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.MagicResist)
                    {
                        temp.propertyValue = soldierProto.MagicResist * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.MaxHealth)
                    {
                        temp.propertyValue = soldierProto.Health * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.PhysicalAttack)
                    {
                        temp.propertyValue = soldierProto.PhysicalAttack * (1 + item.Value[1]) + item.Value[0];
                    }
                    else if (temp.propertyType == PropertyType.Speed)
                    {
                        temp.propertyValue = soldierProto.MoveSpeed * (1 + item.Value[1]) + item.Value[0];
                    }
                    else
                    {
                        DebugUtils.LogError(DebugUtils.Type.Battle, "Can't find this proptyType" + temp.propertyType);
                    }

                    unit.props.Add(temp);
                }

                // fill unit's gear data
                //for ( int j = 0; j < s.items.Count; j++ )
                //{
                //    // itemType == 1 means this item is a GearItem
                //    if ( s.items[j].itemType == 1 )
                //    {
                //        unit.gearMetaId.Add( (int)s.items[j].metaId );
                //    }
                //}

                //fill unit's propertyInfo
                //for ( int j = 0; j < s..Count; j++ )
                //{
                //    PropertyInfo p = new PropertyInfo();
                //    p.propertyType = s.props[j].propertyType;
                //    p.propertyValue = s.props[j].propertyValue;
                //}

                //unit.level = s.level;
                //unit.star = s.star;
                battleUnits.Add(unit);
            }
        }