Inheritance: MonoBehaviour
Beispiel #1
0
    //--------------------
    // ADD CHARACTERS
    //--------------------

    public void Add()
    {
        if (Character.characters.Count >= 2 * bus.amountOfRanks - 1)
        {
            ui.Log("Your bus is full !");
        }
        else
        {
            Character chara = Instantiate(
                characterPrefab,
                Vector3.zero,
                Quaternion.identity,
                GameManager.Instance.bus.characterHolder.transform
                ).GetComponent <Character>();

            CharacterIcon charaIcon = Instantiate(
                characterIconPrefab,
                Vector3.zero,
                Quaternion.identity,
                GameManager.Instance.uIManager.sideMenu.transform
                ).GetComponent <CharacterIcon>();

            chara.icon = charaIcon;
            Material color = materials[Random.Range(0, materials.Count)];
            chara.SetColor(color);
            chara.icon.icon.color = color.color;
            chara.name            = names[Random.Range(0, names.Count)];
        }
    }
Beispiel #2
0
        private void InitializeCharacters()
        {
            IEnumerable <Character> chars = CharacterManager.Instance.Characters;

            MondstadtCharacters = chars
                                  .Where(item => TalentHelper.IsTodaysMondstadtMaterial(item.TalentMaterial))
                                  .Where(item => CharacterManager.UnreleasedPolicyFilter(item))
                                  .OrderByDescending(item => item.Star)
                                  .Select(item =>
            {
                CharacterIcon c = new CharacterIcon()
                {
                    Character = item
                };
                c.IconClicked += OnCharacterClicked;
                return(c);
            });
            LiyueCharacters = chars
                              .Where(item => TalentHelper.IsTodaysLiyueMaterial(item.TalentMaterial))
                              .Where(item => CharacterManager.UnreleasedPolicyFilter(item))
                              .OrderByDescending(item => item.Star)
                              .Select(item =>
            {
                CharacterIcon c = new CharacterIcon()
                {
                    Character = item
                };
                c.IconClicked += OnCharacterClicked;
                return(c);
            });
        }
    public void InitializeCharacterPanel()
    {
        _battleSystem = GetComponentInParent <BattleSystem>();
        _battleField  = FindObjectOfType <BattleField>();
        _targetIcon   = FindObjectOfType <TargetIcon>();

        foreach (PlayerBattlePlacement pb in _battleField._playerBattlePlacement)
        {
            if (pb._battlePosition == _characterPanelNumber)
            {
                _myCharacter = pb._mycharacterBattler;
            }
        }

        if (_myCharacter == null)
        {
            return;                       /// Stop the Initialization
        }
        _characterIcon      = _myCharacter.GetComponentInChildren <CharacterIcon>();
        _characterAbilities = _myCharacter.GetComponent <CharacterAbilities>();

        _targetManager  = new TargetManager(_battleField._playerBattlePlacement, _battleField._enemyBattlePlacement, _characterAbilities, _targetIcon);
        _uiPanelChanger = GetComponent <UIPanelChanger>();

        _magicPanelManager = GetComponentInChildren <MagicPanelManager>();
        _magicPanelManager.InitializeMagicPanels(_characterAbilities._classSkills);

        _isInitialized = true;
    }
Beispiel #4
0
    void OnTriggerEnter(Collider col) {
        if (col.gameObject.CompareTag("Player") && affected.Contains(col.gameObject.GetComponent<CharacterStatus>().characterName)) {

            icon = col.gameObject.GetComponentInChildren<CharacterIcon>();
            icon.ActiveCanvas(true);
            icon.SetImage(tooltipImage);

        }
    }
Beispiel #5
0
 protected void changeIcon(GameObject typeIcon)
 {
     if (typeIcon != null)
     {
         prevIcon = currIcon;
         currIcon = typeIcon;
         cIcon    = currIcon.GetComponent <CharacterIcon>(); // cIconを更新
         cIcon.setIcon(playerType, prevIcon);
     }
 }
 public static IEnumerable <CharacterIcon> AsCharacterIcon(this IEnumerable <Character> characters, bool isSmall = false) => characters.Select(c =>
 {
     CharacterIcon characterIcon = new CharacterIcon()
     {
         Character = c
     };
     if (isSmall)
     {
         characterIcon.Width  = 50;
         characterIcon.Height = 50;
     }
     return(characterIcon);
 });
Beispiel #7
0
    private void HideCharacterTooltip() {
        // Desactiva el tooltip si se está mostrando
        if (icon != null) {
            icon.ActiveCanvas(false);
            icon = null;
        }
        if (requiredAbility != null) {
            // Informa a la habilidad que el objeto ya no se encuentra disponible
            requiredAbility.SetReady(false);
        } else if (usableObj != null) {
            // Deshabilita el objeto usable
            usableObj.canUse = false;
        }

    }
    // 選択アイコンが切り替わる度にonPlayerを変更する
    public void setIcon(PlayerType playerType, GameObject prevIcon)
    {
        CharacterIcon cIcon = prevIcon.GetComponent <CharacterIcon>();

        switch (playerType)
        {
        case PlayerType.Player_1:
            onPlayer1       = true;
            cIcon.onPlayer1 = false;
            break;

        case PlayerType.Player_2:
            onPlayer2       = true;
            cIcon.onPlayer2 = false;
            break;

        default:
            break;
        }

        um.setCharaData(playerType, Character.GetComponent <Character>());
    }
Beispiel #9
0
    }                                                 // 選択したキャラクター

    // Use this for initialization
    protected void Start()
    {
        cIcon = currIcon.GetComponent <CharacterIcon>();
        GameObject.Find("Canvas").GetComponent <UIManager>().setCharaData(playerType, cIcon.Character);
        cIcon.initSetIcon(playerType);
    }
Beispiel #10
0
        public override void draw(SpriteBatch b)
        {
            string title = _translation.Get("ui.tasks.new");
            int    iconY = okButton.bounds.Y;

            b.Draw(Game1.fadeToBlackRect, Game1.graphics.GraphicsDevice.Viewport.Bounds, Color.Black * 0.75f);
            SpriteText.drawStringWithScrollCenteredAt(b, title, xPositionOnScreen + width / 2, yPositionOnScreen - 96);

            _textBox.Draw(b);

            if (closeTipButton.visible = DeluxeJournalMod.Instance?.Config?.ShowSmartAddTip ?? true)
            {
                string text             = Game1.parseText(_translation.Get("ui.tasks.new.smarttip"), Game1.smallFont, 396);
                int    extraLineSpacing = Math.Max(0, text.Count(c => c == '\n') - 1) * Game1.smallFont.LineSpacing;

                DrawInfoBox(b, text, new Rectangle(_textBox.X - 32, _textBox.Y + 34, 544, 140 + extraLineSpacing));
                iconY += 80 + extraLineSpacing;

                if (new Rectangle(_textBox.X, _textBox.Y + 72, 480, 76).Contains(Game1.getOldMouseX(), Game1.getOldMouseY()))
                {
                    closeTipButton.draw(b);
                }
            }

            optionsButton.draw(b);
            cancelButton.draw(b);
            okButton.draw(b, (_textBox.Text.Length > 0) ? Color.White : Color.Gray * 0.8f, 0.88f);
            smartOkButton.draw(b, (_textBox.Text.Length > 0 && _taskParser.MatchFound()) ? Color.White : Color.Gray * 0.8f, 0.88f);

            if (smartTypeIconCC.visible = _taskParser.MatchFound())
            {
                Item?  item = _taskParser.SmartIconItem;
                NPC?   npc  = _taskParser.SmartIconNPC;
                string?name = _taskParser.SmartIconName;

                smartTypeIconCC.bounds.Y = iconY;
                smartItemIcon.bounds.Y   = iconY;
                smartNPCIcon.bounds.Y    = iconY;
                smartNameIcon.bounds.Y   = iconY;

                smartItemIcon.visible = item != null;
                smartNPCIcon.visible  = npc != null;
                smartNameIcon.visible = name != null;

                TaskRegistry.GetTaskIcon(_taskParser.ID).DrawIcon(b, smartTypeIconCC.bounds, Color.White);
                smartNameIcon.draw(b);

                if (npc != null)
                {
                    smartNPCIcon.draw(b);
                    CharacterIcon.DrawIcon(b, npc.Name, new Rectangle(smartNPCIcon.bounds.X + 8, smartNPCIcon.bounds.Y + 8, 40, 40));
                }

                if (item != null)
                {
                    smartItemIcon.bounds.X = smartNPCIcon.bounds.X + (smartNPCIcon.visible ? smartItemIcon.bounds.Width + 4 : 0);
                    smartItemIcon.draw(b);

                    item.drawInMenu(b,
                                    new Vector2(smartItemIcon.bounds.X - (item.ParentSheetIndex == SObject.wood ? 6 : 2), smartItemIcon.bounds.Y - 2),
                                    0.75f, 1.0f, 0.9f,
                                    StackDrawType.Draw,
                                    Color.White,
                                    false);
                }
            }

            if (_hoverText.Length > 0)
            {
                drawHoverText(b, _hoverText, Game1.dialogueFont);
            }
        }
Beispiel #11
0
        private static void CheckEntryStatus(GameDateTime current, string ipAddress, Character chara, string password, CharacterIcon icon, Town town, Country country, bool isCountryFree)
        {
            if (string.IsNullOrEmpty(ipAddress))
            {
                ErrorCode.InvalidIpAddressError.Throw();
            }

            if (string.IsNullOrEmpty(password))
            {
                ErrorCode.LackOfParameterError.Throw();
            }
            if (password.Length < 4 || password.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("password", password.Length, 4, 12));
            }
            if (string.IsNullOrEmpty(chara.Name))
            {
                ErrorCode.LackOfNameParameterError.Throw();
            }
            if (chara.Name.Contains('_'))
            {
                ErrorCode.NotPermissionError.Throw();
            }
            if (chara.Name.Length < 1 || chara.Name.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("name", chara.Name.Length, 1, 12));
            }
            if (string.IsNullOrEmpty(chara.AliasId))
            {
                ErrorCode.LackOfParameterError.Throw();
            }
            if (chara.AliasId.Length < 4 || chara.AliasId.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("aliasId", chara.AliasId.Length, 4, 12));
            }

            if (icon.Type == CharacterIconType.Default)
            {
                var iconIdStr = icon.FileName.Split('.');
                if (uint.TryParse(iconIdStr[0], out uint iconId))
                {
                    if (iconId < 0 || iconId > 99)
                    {
                        ErrorCode.CharacterIconNotFoundError.Throw();
                    }
                }
                else
                {
                    ErrorCode.CharacterIconNotFoundError.Throw();
                }
            }
            else if (icon.Type == CharacterIconType.Gravatar)
            {
                if (string.IsNullOrEmpty(icon.FileName))
                {
                    ErrorCode.LackOfParameterError.Throw();
                }
            }
            else
            {
                ErrorCode.InvalidParameterError.Throw();
            }

            if (chara.From == CharacterFrom.Unknown)
            {
                ErrorCode.LackOfParameterError.Throw();
            }

            var formation = FormationTypeInfoes.Get(chara.FormationType);

            if (formation.HasData)
            {
                if (!formation.Data.IsAvailable)
                {
                    ErrorCode.InvalidParameterError.Throw();
                }
            }

            var attributeMax    = GetAttributeMax(current);
            var attributeSumMax = GetAttributeSumMax(current);

            if (chara.Strong < 5 || chara.Intellect < 5 || chara.Leadership < 5 || chara.Popularity < 5)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("attribute", 0, 5, attributeMax));
            }
            if (chara.Strong > attributeMax || chara.Intellect > attributeMax || chara.Leadership > attributeMax || chara.Popularity > attributeMax)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("attribute", 0, 5, attributeMax));
            }
            if (chara.Strong + chara.Intellect + chara.Leadership + chara.Popularity < attributeSumMax - 2) // -2は新規登録情報入力途中に変動した場合の対応
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("sumOfAttribute", 0, attributeSumMax, attributeSumMax));
            }
            if (chara.Strong + chara.Intellect + chara.Leadership + chara.Popularity > attributeSumMax)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("sumOfAttribute", 0, attributeSumMax, attributeSumMax));
            }

            if (country != null && (!string.IsNullOrEmpty(country.Name) || country.CountryColorId != 0))
            {
                if (country.CountryColorId < 1 || country.CountryColorId > Config.CountryColorMax)
                {
                    ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("countryColor", country.CountryColorId, 1, Config.CountryColorMax));
                }
                if (string.IsNullOrEmpty(country.Name) || country.Name.Length < 1 || country.Name.Length > 8)
                {
                    ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("countryName", country.Name.Length, 1, 8));
                }
                if (town.CountryId > 0)
                {
                    ErrorCode.CantPublisAtSuchTownhError.Throw();
                }
            }
            else
            {
                if (town.CountryId <= 0 && !isCountryFree)
                {
                    ErrorCode.CantJoinAtSuchTownhError.Throw();
                }
            }
        }
Beispiel #12
0
        public static async Task EntryAsync(MainRepository repo, string ipAddress, Character newChara, CharacterIcon newIcon, string password, Country newCountry, string invitationCode, bool isFreeCountry)
        {
            var town = await repo.Town.GetByIdAsync(newChara.TownId).GetOrErrorAsync(ErrorCode.TownNotFoundError);

            var system = await repo.System.GetAsync();

            CheckEntryStatus(system.GameDateTime, ipAddress, newChara, password, newIcon, town, newCountry, isFreeCountry);

            // 文字数チェックしてからエスケープ
            newChara.Name    = HtmlUtil.Escape(newChara.Name);
            newCountry.Name  = HtmlUtil.Escape(newCountry.Name);
            newChara.Message = HtmlUtil.Escape(newChara.Message);

            // 既存との重複チェック
            if (await repo.Character.IsAlreadyExistsAsync(newChara.Name, newChara.AliasId))
            {
                ErrorCode.DuplicateCharacterNameOrAliasIdError.Throw();
            }
            if ((system.IsDebug && (await repo.System.GetDebugDataAsync()).IsCheckDuplicateEntry || !system.IsDebug) &&
                await repo.EntryHost.ExistsAsync(ipAddress))
            {
                ErrorCode.DuplicateEntryError.Throw();
            }

            // 招待コードチェック
            Optional <InvitationCode> invitationCodeOptional = default;

            if (system.InvitationCodeRequestedAtEntry)
            {
                invitationCodeOptional = await repo.InvitationCode.GetByCodeAsync(invitationCode);

                if (!invitationCodeOptional.HasData || invitationCodeOptional.Data.HasUsed || invitationCodeOptional.Data.Aim != InvitationCodeAim.Entry)
                {
                    ErrorCode.InvitationCodeRequestedError.Throw();
                }
            }

            var    updateCountriesRequested = false;
            MapLog maplog = null;
            var    chara  = new Character
            {
                Name                = newChara.Name,
                AliasId             = newChara.AliasId,
                Strong              = newChara.Strong,
                StrongEx            = 0,
                Intellect           = newChara.Intellect,
                IntellectEx         = 0,
                Leadership          = newChara.Leadership,
                LeadershipEx        = 0,
                Popularity          = newChara.Popularity,
                PopularityEx        = 0,
                Contribution        = 0,
                Class               = 0,
                DeleteTurn          = (short)(Config.DeleteTurns - 10),
                LastUpdated         = DateTime.Now,
                LastUpdatedGameDate = system.GameDateTime,
                Message             = newChara.Message,
                Money               = 10_0000 + Math.Max(system.GameDateTime.ToInt() - (Config.StartYear + Config.UpdateStartYear + 4) * 12 - Config.StartMonth, 0) * 800,
                Rice                = 5_0000 + Math.Max(system.GameDateTime.ToInt() - (Config.StartYear + Config.UpdateStartYear + 4) * 12 - Config.StartMonth, 0) * 400,
                SkillPoint          = Math.Max(0, (int)((system.IntGameDateTime - Config.UpdateStartYear * 12) * 0.8f)),
                SoldierType         = SoldierType.Common,
                SoldierNumber       = 0,
                Proficiency         = 0,
                TownId              = newChara.TownId,
                From                = newChara.From,
                Religion            = ReligionType.Any,
                FormationType       = newChara.FormationType,
                IsBeginner          = newChara.IsBeginner,
            };

            chara.SetPassword(password);

            // 出身
            var skills = new List <CharacterSkillType>();
            var items  = new List <CharacterItemType>();

            if (chara.From == CharacterFrom.Warrior)
            {
                skills.Add(CharacterSkillType.Strong1);
                chara.Strong += 20;
            }
            else if (chara.From == CharacterFrom.Civilian)
            {
                skills.Add(CharacterSkillType.Intellect1);
                chara.Intellect += 20;
            }
            else if (chara.From == CharacterFrom.Merchant)
            {
                skills.Add(CharacterSkillType.Merchant1);
                chara.Money += 200000;
            }
            else if (chara.From == CharacterFrom.Engineer)
            {
                skills.Add(CharacterSkillType.Engineer1);
                chara.Strong += 10;
                chara.Money  += 100000;
            }
            else if (chara.From == CharacterFrom.Terrorist)
            {
                skills.Add(CharacterSkillType.Terrorist1);
                chara.Strong     += 15;
                chara.Leadership += 5;
            }
            else if (chara.From == CharacterFrom.People)
            {
                skills.Add(CharacterSkillType.People1);
                chara.Popularity += 20;
            }
            else if (chara.From == CharacterFrom.Tactician)
            {
                skills.Add(CharacterSkillType.Tactician1);
                chara.Strong     += 5;
                chara.Leadership += 15;
            }
            else if (chara.From == CharacterFrom.Scholar)
            {
                skills.Add(CharacterSkillType.Scholar1);
                chara.Intellect += 20;
            }
            else if (chara.From == CharacterFrom.Staff)
            {
                skills.Add(CharacterSkillType.Staff1);
                chara.Intellect += 20;
            }
            else if (chara.From == CharacterFrom.Buddhism)
            {
                if (system.RuleSet == GameRuleSet.SimpleBattle)
                {
                    ErrorCode.RuleSetError.Throw();
                }
                skills.Add(CharacterSkillType.Buddhism1);
                chara.Intellect += 15;
                chara.Religion   = ReligionType.Buddhism;
            }
            else if (chara.From == CharacterFrom.Confucianism)
            {
                if (system.RuleSet == GameRuleSet.SimpleBattle)
                {
                    ErrorCode.RuleSetError.Throw();
                }
                skills.Add(CharacterSkillType.Confucianism1);
                chara.Intellect += 15;
                chara.Religion   = ReligionType.Confucianism;
            }
            else if (chara.From == CharacterFrom.Taoism)
            {
                if (system.RuleSet == GameRuleSet.SimpleBattle)
                {
                    ErrorCode.RuleSetError.Throw();
                }
                skills.Add(CharacterSkillType.Taoism1);
                chara.Intellect += 15;
                chara.Religion   = ReligionType.Taoism;
            }
            else
            {
                ErrorCode.InvalidParameterError.Throw();
            }

            // 来月の更新がまだ終わってないタイミングで登録したときの、武将更新時刻の調整
            if (chara.LastUpdated - system.CurrentMonthStartDateTime > TimeSpan.FromSeconds(Config.UpdateTime))
            {
                chara.IntLastUpdatedGameDate++;
            }

            if (isFreeCountry)
            {
                // 無所属で開始
                chara.CountryId = 0;
                await repo.Character.AddAsync(chara);

                maplog = new MapLog
                {
                    Date            = DateTime.Now,
                    ApiGameDateTime = system.GameDateTime,
                    EventType       = EventType.CharacterEntryToFree,
                    IsImportant     = false,
                    Message         = $"<character>{chara.Name}</character> が無所属に出現しました",
                };
                await repo.MapLog.AddAsync(maplog);
            }
            else if (town.CountryId > 0)
            {
                // 武将総数チェック
                var country = await repo.Country.GetByIdAsync(town.CountryId).GetOrErrorAsync(ErrorCode.CountryNotFoundError);

                if (country.IntEstablished + Config.CountryBattleStopDuring > system.GameDateTime.ToInt())
                {
                    var countryCharaCount = await repo.Country.CountCharactersAsync(country.Id, true);

                    if (countryCharaCount >= Config.CountryJoinMaxOnLimited)
                    {
                        ErrorCode.CantJoinAtSuchCountryhError.Throw();
                    }
                    else if (countryCharaCount + 1 == Config.CountryJoinMaxOnLimited)
                    {
                        updateCountriesRequested = true;
                    }
                }

                // AI国家チェック
                if (country.AiType != CountryAiType.Human)
                {
                    ErrorCode.CantJoinAtSuchCountryhError.Throw();
                }

                // 金と米を仕官先国の武将の平均にあわせる
                if (system.GameDateTime.Year >= Config.UpdateStartYear + Config.CountryBattleStopDuring / 12)
                {
                    var countryCharacters = (await repo.Country.GetCharactersAsync(town.CountryId)).Where(c => c.AiType == CharacterAiType.Human || c.AiType == CharacterAiType.Administrator);
                    if (countryCharacters.Any())
                    {
                        chara.Money = Math.Min((int)countryCharacters.Average(c => c.Money) + 10_0000, chara.Money);
                        chara.Rice  = Math.Min((int)countryCharacters.Average(c => c.Rice) + 5_0000, chara.Rice);
                    }
                }

                chara.CountryId = town.CountryId;
                await repo.Character.AddAsync(chara);

                maplog = new MapLog
                {
                    Date            = DateTime.Now,
                    ApiGameDateTime = system.GameDateTime,
                    EventType       = EventType.CharacterEntry,
                    IsImportant     = false,
                    Message         = $"<character>{chara.Name}</character> が <country>{country.Name}</country> に仕官しました",
                };
                await repo.MapLog.AddAsync(maplog);
            }
            else
            {
                // 重複チェック
                if ((await repo.Country.GetAllAsync()).Any(c => c.Name == newCountry.Name || c.CountryColorId == newCountry.CountryColorId))
                {
                    ErrorCode.DuplicateCountryNameOrColorError.Throw();
                }

                if (system.RuleSet == GameRuleSet.SimpleBattle)
                {
                    newCountry.Civilization = CountryCivilization.None;
                }

                var country = new Country
                {
                    Name           = newCountry.Name,
                    CountryColorId = newCountry.CountryColorId,
                    CapitalTownId  = newChara.TownId,
                    IntEstablished = Math.Max(system.GameDateTime.ToInt(), new GameDateTime {
                        Year = Config.UpdateStartYear, Month = 1,
                    }.ToInt()),
                    HasOverthrown         = false,
                    IntOverthrownGameDate = 0,
                    LastMoneyIncomes      = 0,
                    LastRiceIncomes       = 0,
                    PolicyPoint           = 10000,
                    Religion     = RandomService.Next(new ReligionType[] { ReligionType.Buddhism, ReligionType.Confucianism, ReligionType.Taoism, }),
                    Civilization = newCountry.Civilization,
                };
                updateCountriesRequested = true;
                await repo.Country.AddAsync(country);

                var countries = await repo.Country.GetAllAsync();

                var point = 500;

                if (system.RuleSet != GameRuleSet.Wandering)
                {
                    // 大都市に変更
                    town.SubType = town.Type;
                    MapService.UpdateTownType(town, TownType.Large);

                    // 首都の宗教
                    if (system.RuleSet != GameRuleSet.SimpleBattle)
                    {
                        if (country.Religion == ReligionType.Buddhism)
                        {
                            town.Buddhism    += point;
                            town.Confucianism = Math.Min(town.Confucianism, 999);
                            town.Taoism       = Math.Min(town.Taoism, 999);
                        }
                        if (country.Religion == ReligionType.Confucianism)
                        {
                            town.Confucianism += point;
                            town.Buddhism      = Math.Min(town.Buddhism, 999);
                            town.Taoism        = Math.Min(town.Taoism, 999);
                        }
                        if (country.Religion == ReligionType.Taoism)
                        {
                            town.Taoism      += point;
                            town.Buddhism     = Math.Min(town.Buddhism, 999);
                            town.Confucianism = Math.Min(town.Confucianism, 999);
                        }
                    }
                }
                else
                {
                    country.CapitalTownId = 0;
                    items.Add(CharacterItemType.CastleBlueprint);
                    items.Add(CharacterItemType.CastleBlueprint);
                    items.Add(CharacterItemType.CastleBlueprint);
                    chara.Money += 50_0000 * 3;
                }

                await repo.SaveChangesAsync();

                chara.CountryId = country.Id;
                if (system.RuleSet != GameRuleSet.Wandering)
                {
                    town.CountryId = country.Id;
                }
                await repo.Character.AddAsync(chara);

                await repo.SaveChangesAsync();

                var countryPost = new CountryPost
                {
                    Type        = CountryPostType.Monarch,
                    CountryId   = country.Id,
                    CharacterId = chara.Id,
                };
                await repo.Country.AddPostAsync(countryPost);

                if (system.RuleSet == GameRuleSet.Wandering)
                {
                    maplog = new MapLog
                    {
                        Date            = DateTime.Now,
                        ApiGameDateTime = system.GameDateTime,
                        EventType       = EventType.StartWandering,
                        IsImportant     = true,
                        Message         = $"<character>{chara.Name}</character> は <country>{country.Name}</country> の頭領となり放浪を開始しました",
                    };
                }
                else
                {
                    maplog = new MapLog
                    {
                        Date            = DateTime.Now,
                        ApiGameDateTime = system.GameDateTime,
                        EventType       = EventType.Publish,
                        IsImportant     = true,
                        Message         = $"<character>{chara.Name}</character> が <town>{town.Name}</town> に <country>{country.Name}</country> を建国しました",
                    };
                }
                await repo.MapLog.AddAsync(maplog);
            }

            await repo.SaveChangesAsync();

            // 陣形
            var formation = new Formation
            {
                CharacterId = chara.Id,
                Type        = chara.FormationType,
                Level       = 1,
            };
            await repo.Character.AddFormationAsync(formation);

            if (invitationCodeOptional.HasData)
            {
                var code = invitationCodeOptional.Data;
                code.HasUsed     = true;
                code.Used        = DateTime.Now;
                code.CharacterId = chara.Id;
            }

            var icon = new CharacterIcon
            {
                Type        = newIcon.Type,
                IsAvailable = true,
                IsMain      = true,
                FileName    = newIcon.FileName,
                CharacterId = chara.Id,
            };
            await repo.Character.AddCharacterIconAsync(icon);

            var host = new EntryHost
            {
                CharacterId = chara.Id,
                IpAddress   = ipAddress,
            };
            await repo.EntryHost.AddAsync(host);

            var skillItems = skills.Select(s => new CharacterSkill
            {
                CharacterId = chara.Id,
                Type        = s,
                Status      = CharacterSkillStatus.Available,
            });

            foreach (var si in skillItems)
            {
                await SkillService.SetCharacterAndSaveAsync(repo, si, chara);
            }
            var itemData = items.Select(i => new CharacterItem
            {
                Type        = i,
                CharacterId = chara.Id,
                Status      = CharacterItemStatus.CharacterHold,
            });

            foreach (var id in itemData)
            {
                await ItemService.GenerateItemAndSaveAsync(repo, id);
            }

            await repo.SaveChangesAsync();

            if (updateCountriesRequested)
            {
                var countries = await repo.Country.GetAllForAnonymousAsync();

                await AnonymousStreaming.Default.SendAllAsync(countries.Select(c => ApiData.From(c)));

                await StatusStreaming.Default.SendAllAsync(countries.Select(c => ApiData.From(c)));
            }

            var townData   = ApiData.From(new TownForAnonymous(town));
            var maplogData = ApiData.From(maplog);
            await AnonymousStreaming.Default.SendAllAsync(maplogData);

            await StatusStreaming.Default.SendAllAsync(maplogData);

            await AnonymousStreaming.Default.SendAllAsync(townData);

            await StatusStreaming.Default.SendAllAsync(townData);

            await StatusStreaming.Default.SendCountryAsync(ApiData.From(town), town.CountryId);

            await CharacterService.StreamCharacterAsync(repo, chara);
        }
Beispiel #13
0
 void ShowCharacterTooltip(GameObject character) {
     if (CharacterManager.IsActiveCharacter(character)) {
         if (TooltipHasToBeShown(character)) {
             if ((TooltipManager.On) && (tooltipImage != null)) {
                 icon = character.GetComponentInChildren<CharacterIcon>();
                 icon.ActiveCanvas(true);
                 icon.SetImage(tooltipImage);
             }
         } else {
             HideCharacterTooltip();
         }
     }
 }
Beispiel #14
0
        public static async Task ResetAsync(MainRepository repo)
        {
            var now    = DateTime.Now;
            var system = await repo.System.GetAsync();

            var history = await repo.History.GetAsync(system.Period, system.BetaVersion);

            if (history.HasData)
            {
                var countries = await repo.Country.GetAllAsync();

                var messages = await repo.ChatMessage.GetAllAsync();

                history.Data.ChatMessages = messages.Select(m => HistoricalChatMessage.FromChatMessage(m)).ToArray();
                await repo.History.RecordChatMessagesAndSaveAsync(history.Data);

                var            unifiedCountry        = countries.FirstOrDefault(c => !c.HasOverthrown);
                CountryMessage unifiedCountryMessage = null;
                if (unifiedCountry != null)
                {
                    var msgs = await repo.Country.GetMessagesAsync(CountryMessageType.Unified);

                    unifiedCountryMessage = msgs.FirstOrDefault();
                }
                if (unifiedCountryMessage != null)
                {
                    history.Data.UnifiedCountryMessage = unifiedCountryMessage.Message;
                }
            }

            await OnlineService.ResetAsync();

            await repo.AuthenticationData.ResetAsync();

            await repo.BattleLog.ResetAsync();

            await repo.CharacterItem.ResetAsync();

            await repo.CharacterCommand.ResetAsync();

            await repo.Character.ResetAsync();

            await repo.EntryHost.ResetAsync();

            await repo.ChatMessage.ResetAsync();

            await repo.CountryDiplomacies.ResetAsync();

            await repo.AiCountry.ResetAsync();

            await repo.AiActionHistory.ResetAsync();

            await repo.Country.ResetAsync();

            await repo.MapLog.ResetAsync();

            await repo.ScoutedTown.ResetAsync();

            await repo.ThreadBbs.ResetAsync();

            await repo.Town.ResetAsync();

            await repo.Unit.ResetAsync();

            await repo.Reinforcement.ResetAsync();

            await repo.DelayEffect.ResetAsync();

            await repo.Mute.ResetAsync();

            // await repo.PushNotificationKey.ResetAsync();
            await repo.BlockAction.ResetAsync();

            // ファイル削除
            try
            {
                foreach (var file in System.IO.Directory.GetFiles(Config.Game.UploadedIconDirectory).Where(f => !f.EndsWith(".txt", StringComparison.Ordinal)))
                {
                    System.IO.File.Delete(file);
                }
            }
            catch
            {
                // Loggerがない!
            }

            await ResetTownsAndSaveAsync(repo, system.RuleSetNextPeriod);

            system.GameDateTime = new GameDateTime
            {
                Year  = Config.StartYear,
                Month = Config.StartMonth,
            };
            system.CurrentMonthStartDateTime = new DateTime(now.Year, now.Month, now.Day, 20, 0, 0, 0);
            system.IsWaitingReset            = false;
            system.IntResetGameDateTime      = 0;
            system.TerroristCount            = 0;
            system.ManagementCountryCount    = 0;
            system.IsBattleRoyaleMode        = false;
            system.RuleSet           = system.RuleSetNextPeriod;
            system.RuleSetNextPeriod = system.RuleSetAfterNextPeriod;
            system.IsSoftStoped      = false;

            if (system.BetaVersion == 0 && (system.Period + 3) % 6 == 0)
            {
                system.RuleSetAfterNextPeriod =
                    RandomService.Next(new GameRuleSet[] {
                    GameRuleSet.SimpleBattle,
                    GameRuleSet.Wandering,
                    GameRuleSet.BattleRoyale,
                    GameRuleSet.Gyokuji,
                    GameRuleSet.Religion,
                });
            }
            else
            {
                system.RuleSetAfterNextPeriod = GameRuleSet.Normal;
            }

            if (system.IsNextPeriodBeta)
            {
                system.BetaVersion++;
            }
            else
            {
                system.BetaVersion = 0;
                system.Period++;
            }

            if (Config.Game.IsGenerateAdminCharacter)
            {
                var admin = new Character
                {
                    Name                = Config.Admin.Name,
                    AiType              = CharacterAiType.Administrator,
                    LastUpdated         = DateTime.Now,
                    LastUpdatedGameDate = system.GameDateTime,
                    TownId              = (await repo.Town.GetAllAsync()).First().Id,
                    AliasId             = Config.Admin.AliasId,
                    Money               = 1000_0000,
                };
                admin.SetPassword(Config.Admin.Password);
                await repo.Character.AddAsync(admin);

                await repo.SaveChangesAsync();

                var adminIcon = new CharacterIcon
                {
                    CharacterId = admin.Id,
                    IsAvailable = true,
                    IsMain      = true,
                    Type        = CharacterIconType.Gravatar,
                    FileName    = Config.Admin.GravatarMailAddressMD5,
                };
                await repo.Character.AddCharacterIconAsync(adminIcon);
            }


            var ruleSetName = system.RuleSet == GameRuleSet.Normal ? "標準" :
                              system.RuleSet == GameRuleSet.Wandering ? "放浪" :
                              system.RuleSet == GameRuleSet.SimpleBattle ? "原理" :
                              system.RuleSet == GameRuleSet.BattleRoyale ? "全国戦争" :
                              system.RuleSet == GameRuleSet.Gyokuji ? "玉璽" :
                              system.RuleSet == GameRuleSet.Religion ? "宗教" : "";
            await repo.MapLog.AddAsync(new MapLog
            {
                EventType       = EventType.Reset,
                Date            = DateTime.Now,
                ApiGameDateTime = system.GameDateTime,
                IsImportant     = true,
                Message         = $"ゲームプログラムを開始しました。今期のルールセットは {ruleSetName} です",
            });

            await repo.SaveChangesAsync();

            await StatusStreaming.Default.SendAllAsync(ApiData.From(new ApiSignal
            {
                Type = SignalType.Reseted,
            }));

            await AnonymousStreaming.Default.SendAllAsync(ApiData.From(new ApiSignal
            {
                Type = SignalType.Reseted,
            }));
        }