Exemplo n.º 1
0
        public void SetView(CombatantInfo unit, SpaceBattleController controller)
        {
            this.unit       = unit;
            this.controller = controller;

            var context       = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var formatter     = new ThousandsFormatter();
            var decimalFormat = new DecimalsFormatter(0, 0);

            shipCount.Text   = context["ShipCount"].Text() + ": " + formatter.Format(unit.Count);
            armorInfo.Text   = hpText("ArmorLabel", unit.ArmorHp, unit.ArmorHpMax);
            shieldsInfo.Text = hpText("ShieldLabel", unit.ShieldHp, unit.ShieldHpMax);

            if (unit.MovementEta > 0)
            {
                movementInfo.Text = context["MovementEta"].Text(
                    new Var("eta", unit.MovementEta).Get,
                    new TextVar("eta", unit.MovementEta.ToString()).Get
                    );
            }
            else
            {
                movementInfo.Text = context["MovementPoints"].Text() + " (" + decimalFormat.Format(unit.MovementPoints * 100) + " %)";
            }
        }
 public void OnUnitTurn(CombatantInfo unitInfo)
 {
     this.currentUnit     = unitInfo;
     this.SelectedAbility = unitInfo.Abilities.FirstOrDefault(x => x.Quantity > 0);
     this.setupBodies();
     this.setupUnits();
 }
Exemplo n.º 3
0
        public void PlayUnit(CombatantInfo unitInfo)
        {
            var destination = unitInfo.ValidMoves.Aggregate(
                unitInfo.Position,
                (a, b) => (Methods.HexDistance(a) <= Methods.HexDistance(b)) ? a : b
                );

            if (destination != unitInfo.Position)
            {
                battleController.MoveTo(destination);
                return;
            }

            if (unitInfo.Position == new Vector2D(0, 0))
            {
                var ability = unitInfo.Abilities.FirstOrDefault();
                if (ability != null && ability.Quantity > 0)
                {
                    battleController.UseAbilityOnStar(ability);
                    return;
                }
            }

            battleController.UnitDone();
        }
Exemplo n.º 4
0
        //TODO(later) assumes unit is catalyzer
        public void PlayUnit(CombatantInfo unitInfo)
        {
            var ability  = unitInfo.Abilities.FirstOrDefault();
            var canShoot = ability != null && ability.Quantity > 0;

            var destination = unitInfo.Position;

            if (unitInfo.ValidMoves.Any())
            {
                destination = canShoot ?
                              Methods.FindWorst(unitInfo.ValidMoves, x => Methods.HexDistance(x)) :
                              Methods.FindBest(unitInfo.ValidMoves, x => Methods.HexDistance(x));
            }

            if (destination != unitInfo.Position)
            {
                battleController.MoveTo(destination);
            }
            else if (unitInfo.Position == new Vector2D(0, 0) && canShoot)
            {
                battleController.UseAbilityOnStar(ability);
            }
            else
            {
                battleController.UnitDone();
            }
        }
Exemplo n.º 5
0
    public static CombatantInfo ConvertToCombatant(AccountManager.ProfileInfo profData)
    {
        CombatantInfo newInfo = new CombatantInfo();

        newInfo.username = profData.username;
        newInfo.clan     = profData.clan;
        newInfo.rank     = profData.rank;
        return(newInfo);
    }
Exemplo n.º 6
0
        public void PlayUnit(CombatantInfo unitInfo)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <CombatantInfo>(PlayUnit), unitInfo);
                return;
            }

            this.combatRenderer.OnUnitTurn(unitInfo);
        }
Exemplo n.º 7
0
    public void Topan_OnPlayerDisconnected(Topan.NetworkPlayer p)
    {
        NetworkingGeneral.currentGameType.RemovePlayer(p.id);
        CombatantInfo pData = (CombatantInfo)p.GetInitialData("dat");

        if (!connectionBanList.Contains(p.peerObject.UniqueIdentifier.ToString()))
        {
            topanNetworkView.RPC(Topan.RPCMode.All, "LeaveMSG", pData.username);
        }

        Topan.Network.DestroyPlayerViews(p.id);
    }
Exemplo n.º 8
0
		public void OnUnitTurn(CombatantInfo unitInfo)
		{
			this.currentUnit = unitInfo;
			this.SelectedAbility = unitInfo.Abilities.FirstOrDefault(x => x.Quantity > 0);

			var unitCenter = new Vector2(hexX(unitInfo.Position), hexY(unitInfo.Position));
			if (!this.isVisible(unitCenter))
			{
				this.originOffset = unitCenter;
				this.setupPerspective();
			}

			this.setupBodies();
			this.setupUnits();
			this.setupProjectiles();
		}
Exemplo n.º 9
0
        public void OnUnitTurn(CombatantInfo unitInfo)
        {
            this.currentUnit = unitInfo;
            this.unitControls.SetView(unitInfo, this.Controller);

            var context    = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var moveButton = new OptionItem <AbilityInfo>(null)
            {
                Text     = context["MoveAction"].Text(),
                OnSelect = x => { this.SelectedAbility = null; }
            };

            var formatter = new ThousandsFormatter();
            var buttons   = new[] { moveButton }.
                Concat(unitInfo.Abilities.Select(
                       ability => new OptionItem <AbilityInfo>(ability)
            {
                Image    = GalaxyTextures.Get.Sprite(ability.ImagePath),
                Text     = ability.Name + " x" + formatter.Format(ability.Quantity),
                OnSelect = x => { this.SelectedAbility = x; }
            }
                       )).ToList();

            foreach (var button in buttons)
            {
                button.GroupWith(moveButton);
            }
            this.abilityList.Children = buttons;
            buttons[buttons.Count > 1 ? 1 : 0].Select();

            var unitCenter = new Vector2(hexX(unitInfo.Position), hexY(unitInfo.Position));

            if (!this.isVisible(unitCenter))
            {
                this.originOffset = unitCenter;
                this.setupPerspective();
            }

            this.setupBodies();
            this.setupUnits();
            this.setupProjectiles();
        }
Exemplo n.º 10
0
    public void Topan_OnPlayerConnected(Topan.NetworkPlayer p)
    {
        if (p.id > 0 && connectionBanList.Contains(p.peerObject.UniqueIdentifier.ToString()))
        {
            topanNetworkView.RPC(new int[1] {
                p.id
            }, "KickPlayer", (byte)1);
            return;
        }

        p.SetPlayerData("k", (UInt16)0);
        p.SetPlayerData("a", (UInt16)0);
        p.SetPlayerData("d", (UInt16)0);
        p.SetPlayerData("h", (UInt16)0);
        p.SetPlayerData("sc", 0);

        int playerTeam = NetworkingGeneral.currentGameType.GetTeamAssign(p.id);

        p.SetPlayerData("team", (byte)playerTeam);

        CombatantInfo pData = (CombatantInfo)p.GetInitialData("dat");

        topanNetworkView.RPC(Topan.RPCMode.All, "JoinMSG", pData.username);

        if (!p.isServer)
        {
            if (!inLobby)
            {
                topanNetworkView.RPC(new int[1] {
                    p.id
                }, "LoadGame", currentMapHash);
            }
            else
            {
                topanNetworkView.RPC(new int[1] {
                    p.id
                }, "LoadLobby");
            }
        }
    }
Exemplo n.º 11
0
        public void PlayUnit(CombatantInfo unitInfo)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new Action <CombatantInfo>(PlayUnit), unitInfo);
                return;
            }

            this.combatRenderer.OnUnitTurn(unitInfo);

            var context       = LocalizationManifest.Get.CurrentLanguage["FormMain"];
            var formatter     = new ThousandsFormatter();
            var decimalFormat = new DecimalsFormatter(0, 0);

            Func <string, double, double, string> hpText = (label, x, max) =>
            {
                var hpFormat = ThousandsFormatter.MaxMagnitudeFormat(x, max);
                return(context[label].Text() + ": " + hpFormat.Format(x) + " / " + hpFormat.Format(max));
            };

            shipCount.Text  = context["ShipCount"].Text() + ": " + formatter.Format(unitInfo.Count);
            armorInfo.Text  = hpText("ArmorLabel", unitInfo.ArmorHp, unitInfo.ArmorHpMax);
            shieldInfo.Text = hpText("ShieldLabel", unitInfo.ShieldHp, unitInfo.ShieldHpMax);

            if (unitInfo.MovementEta > 0)
            {
                movementInfo.Text = context["MovementEta"].Text(
                    new Var("eta", unitInfo.MovementEta).Get,
                    new TextVar("eta", unitInfo.MovementEta.ToString()).Get
                    );
            }
            else
            {
                movementInfo.Text = context["MovementPoints"].Text() + " (" + decimalFormat.Format(unitInfo.MovementPoints * 100) + " %)";
            }

            this.abilityList.Controls.Clear();
            Func <Image, string, object, Button> buttonMaker = (image, text, tag) =>
            {
                var button = new Button
                {
                    Image                   = image,
                    ImageAlign              = ContentAlignment.MiddleLeft,
                    Margin                  = new Padding(3, 3, 3, 0),
                    Size                    = new Size(80, 32),
                    Text                    = text,
                    TextImageRelation       = TextImageRelation.ImageBeforeText,
                    UseVisualStyleBackColor = true,
                    Tag = tag
                };
                button.Click += selectAbility_Click;

                return(button);
            };

            this.abilityList.Controls.Add(buttonMaker(
                                              null,
                                              context["MoveAction"].Text(),
                                              null
                                              ));

            foreach (var ability in unitInfo.Abilities)
            {
                this.abilityList.Controls.Add(buttonMaker(
                                                  ImageCache.Get.Resized(ability.ImagePath, new Size(24, 24)),
                                                  "x " + formatter.Format(ability.Quantity),
                                                  ability
                                                  ));
            }
        }
Exemplo n.º 12
0
    private void AddPlayerToList(int team, Topan.NetworkPlayer player, BotPlayer bot = null)
    {
        int realTeamNum = team;

        if (player != null && !player.HasPlayerData("team"))
        {
            allSuccess = false;
            return;
        }

        bool thisIsBot = (player == null && bot != null);

        if (thisIsBot && team < 2)
        {
            realTeamNum = (int)bot.team;
        }

        GameObject info = GetAvailableSlot();

        if (info == null)
        {
            return;
        }

        bool showInfo = true;
        int  index    = 0;

        if (!GeneralVariables.gameModeHasTeams)
        {
            index = unassignedIndex;

            if (realTeamNum == 2)
            {
                if (index < 8)
                {
                    info.transform.parent = redPanel;
                }
                else
                {
                    info.transform.parent = bluePanel;
                }
            }
            else
            {
                showInfo = false;
            }

            info.transform.localPosition = new Vector3(0f, -(index % 8) * spacing, 0f);
        }
        else
        {
            if (realTeamNum == 0 && redIndex < 8)
            {
                index = redIndex;
                info.transform.parent = redPanel;
            }
            else if (realTeamNum == 1 && blueIndex < 8)
            {
                index = blueIndex;
                info.transform.parent = bluePanel;
            }
            else
            {
                showInfo = false;
            }

            info.transform.localPosition = new Vector3(0f, -index * spacing, 0f);
        }

        info.SetActive(showInfo);
        info.transform.localRotation = Quaternion.identity;
        info.transform.localScale    = Vector3.one;

        PlayerLobbyGUI plg = info.GetComponent <PlayerLobbyGUI>();

        CombatantInfo pInfo = null;

        if (thisIsBot)
        {
            pInfo = bot.botInfo;
        }
        else
        {
            pInfo = (CombatantInfo)player.GetInitialData("dat");
        }

        plg.rankIcon.enabled   = true;
        plg.usernameLabel.text = ((pInfo.clan != "") ? (((thisIsBot) ? (DarkRef.ClanColor(true) + "(" + pInfo.clan + ")") : (DarkRef.ClanColor(false) + "[" + pInfo.clan + "]")) + "[-] ") : "") + pInfo.username;
        plg.rankLabel.text     = pInfo.rank.ToString();

        index++;
        if (!GeneralVariables.gameModeHasTeams)
        {
            if (realTeamNum == 2)
            {
                unassignedIndex = index;
            }
        }
        else
        {
            if (realTeamNum == 0)
            {
                redIndex = index;
            }
            else if (realTeamNum == 1)
            {
                blueIndex = index;
            }
        }
    }
Exemplo n.º 13
0
    public void RefreshPlayerInfo()
    {
        redIndex        = 0;
        blueIndex       = 0;
        unassignedIndex = 0;

        RefreshPlayers();

        if (Topan.Network.isConnected)
        {
            if (Topan.Network.HasServerInfo("m"))
            {
                mapID = (byte)Topan.Network.GetServerInfo("m");
            }
            else
            {
                mapID = -1;
            }

            serverInfo.text = "";
            if (Topan.Network.HasServerInfo("wnr"))
            {
                int winnerteam = ((byte)Topan.Network.GetServerInfo("wnr")) - 1;
                if (winnerteam > -1)
                {
                    serverInfo.text += ((winnerteam == 0) ? "[[C44524]Red Team[-]" : "[[377FB2]Blue Team[-]");
                    serverInfo.text += " Won] \n";
                }
                else
                {
                    serverInfo.text += "[Draw Match] \n";
                }
            }

            int serverDuration = 0;
            if (Topan.Network.HasServerInfo("dur") && Topan.Network.GetServerInfo("dur") != null)
            {
                serverDuration = (byte)Topan.Network.GetServerInfo("dur") * 60;
            }
            else if (Topan.Network.isServer)
            {
                Topan.Network.SetServerInfo("dur", (byte)gameDurationSlider.currentDuration);
            }

            CombatantInfo serverProfile = (CombatantInfo)Topan.Network.server.GetInitialData("dat");
            serverInfo.text += "[D77A39]Room Name:[-] " + Topan.Network.GameName;
            int botsDisp = Mathf.Clamp(GeneralVariables.Networking.botCount, 0, Topan.Network.MaxPlayers - Topan.Network.connectedPlayers.Length);
            serverInfo.text += "\n" + "[D77A39]Players:[-] " + Topan.Network.connectedPlayers.Length + ((botsDisp > 0) ? " [AEBF95][+" + botsDisp.ToString() + "][-]" : "") + "/" + Topan.Network.MaxPlayers;
            serverInfo.text += "\n" + "[D77A39]Host:[-] " + ((serverProfile.clan != "") ? DarkRef.ClanColor(false) + "[" + serverProfile.clan + "][-] " : "") + serverProfile.username;
            serverInfo.text += "\n" + "[D77A39]Game Mode:[-] " + NetworkingGeneral.currentGameType.typeName;
            serverInfo.text += "\n" + "[D77A39]Round Duration:[-] " + (serverDuration / 60).ToString() + " minutes";

            if (mapID > -1)
            {
                serverInfo.text += "\n" + "[D77A39]Map Name:[-] " + StaticMapsList.mapsArraySorted[mapID].mapName;
                serverMapScreenshot.mainTexture = StaticMapsList.mapsArraySorted[mapID].previewIcon;
            }
        }
        else
        {
            serverInfo.text = "Not connected to a network";
            serverMapScreenshot.mainTexture = null;
            mapID = -1;
        }
    }
Exemplo n.º 14
0
    private IEnumerator StartServerCoroutine()
    {
        Topan.Network.AddNetworkEventListener(this);
        TopanData init = new TopanData();

        init.Add("dat", NetworkingGeneral.ConvertToCombatant(AccountManager.profileData));

        int port = 7100; //As default.

        if (portForwardCheckbox.value)
        {
            port = int.Parse(hostPortInput.value);
        }

        PlayerPrefs.SetInt("SavedMaxPlayers", (int)maxPlayerSlider.currentValue);
        PlayerPrefs.SetInt("PortForward", (portForwardCheckbox.value) ? 1 : 0);
        PlayerPrefs.SetInt("LocalServer", (hostLocalCheckbox.value) ? 1 : 0);
        PlayerPrefs.SetString("SavedPingLimit", pingLimitInput.value);
        PlayerPrefs.SetInt("SavedMapIndex", selectedMap);
        PlayerPrefs.SetInt("SavedGameMode", mSettingControl.gameModePopup.selectionIndex);

        Topan.Network.InitializeServer((int)(maxPlayerSlider.currentValue), port, !portForwardCheckbox.value, init);
        Topan.Network.GameName = gameNameInput.value;
        NetworkingGeneral.CreateInstance(cachedNetworking);

        if (!hostLocalCheckbox.value && !portForwardCheckbox.value)
        {
            int mapIndx = selectedMap;
            Topan.MasterServer.RegisterMasterServer(gameNameInput.value, true, AccountManager.profileData.username, mapIndx, gameTypeIndexes[mSettingControl.gameTypeName]);
        }

        GeneralVariables.server.InstantiateServer();

        yield return(null);

        yield return(null);

        UICamera.selectedObject = null;
        Topan.Network.SetServerInfo("s", UnityEngine.Random.seed);
        Topan.Network.SetServerInfo("dur", (byte)gameDurationSlider.currentDuration);
        Topan.Network.SetServerInfo("rc", (byte)roundCountSlider.currentRoundAmount);
        StartCoroutine(SelectMapRoutine(selectedMap));
        GeneralVariables.server.amountOfRounds = roundCountSlider.currentRoundAmount;
        GeneralVariables.lobbyManager.ResetButtons();
        moveCam.TargetPos(new Vector3(3840f, -800f, -700f));

        Topan.Network.SetServerInfo("sm", false);
        Topan.Network.SetServerInfo("rTK", (UInt16)0);
        Topan.Network.SetServerInfo("bTK", (UInt16)0);
        Topan.Network.SetServerInfo("rTD", (UInt16)0);
        Topan.Network.SetServerInfo("bTD", (UInt16)0);
        Topan.Network.SetServerInfo("rVic", (byte)0);
        Topan.Network.SetServerInfo("bVic", (byte)0);

        Topan.Network.SetServerInfo("gm", NetworkingGeneral.currentGameType.typeName);
        foreach (GM_SettingsControl.SettingInfo sInfo in mSettingControl.settingsList)
        {
            Topan.Network.SetServerInfo(sInfo.settingName, NetworkingGeneral.currentGameType.customSettings[sInfo.settingName].currentValue);
        }

        int setPingLimit = Mathf.Clamp(int.Parse(pingLimitInput.value), 100, 9999);

        GeneralVariables.server.pingLimit = setPingLimit;
        Topan.Network.SetServerInfo("plim", setPingLimit);
        Topan.Network.SetServerInfo("it", (byte)(idleTimeSlider.currentIdleTime / 5));

        yield return(null);

        Topan.Network.SetServerInfo("bC", (byte)bsMenu.amountSlider.currentValue);

        BotPlayer[]   newBots   = new BotPlayer[16]; //16 = maximum limit of players in a server
        List <string> prevNames = new List <string>();

        for (int i = 0; i < newBots.Length; i++)
        {
            CombatantInfo newInfo = new CombatantInfo();

            string randomName = DarkRef.RandomBotName();
            int    trials     = 0;
            while (prevNames.Contains(randomName) && trials < 10)
            {
                randomName = DarkRef.RandomBotName();
                trials++;
            }

            newInfo.username = randomName;
            prevNames.Add(randomName);

            newInfo.clan = "BOT";
            newInfo.rank = UnityEngine.Random.Range(1, 11);

            newBots[i]         = new BotPlayer();
            newBots[i].botInfo = newInfo;

            newBots[i].botStats           = new BotStats();
            newBots[i].team               = (byte)(i % 2);
            newBots[i].botStats.kills     = 0;
            newBots[i].botStats.deaths    = 0;
            newBots[i].botStats.headshots = 0;
            newBots[i].botStats.score     = 0;
            Topan.Network.SetServerInfo("bS" + i.ToString(), BotManager.ParseToBotFormat(newBots[i].botStats));
        }

        prevNames         = null;
        BotManager._sBots = newBots;
        Topan.Network.SetServerInfo("bots", newBots);
    }
 public void UseAbility(AbilityInfo ability, CombatantInfo target)
 {
     this.battleGame.Processor.UseAbility(ability.Index, ability.Quantity, target.Data);
     this.checkNextUnit();
 }
 public void UseAbility(AbilityInfo ability, CombatantInfo target)
 {
     this.messageQueue.Add(() => this.processor.UseAbility(ability.Index, ability.Quantity, target.Data));
 }
Exemplo n.º 17
0
 public void PlayUnit(CombatantInfo unitInfo)
 {
     this.battleController.UnitDone();
 }
Exemplo n.º 18
0
    public void AddToKillFeed(byte kID, byte vID, byte wepIndex)
    {
        Topan.NetworkPlayer killer    = null;
        Topan.NetworkPlayer victim    = null;
        BotPlayer           killerBot = null;
        BotPlayer           victimBot = null;

        bool killerIsBot = (kID >= 64);
        bool victimIsBot = (vID >= 64);

        if (killerIsBot)
        {
            killerBot = BotManager.allBotPlayers[kID - 64];
        }
        else
        {
            killer = Topan.Network.GetPlayerByID(kID);
        }

        if (victimIsBot)
        {
            victimBot = BotManager.allBotPlayers[vID - 64];
        }
        else
        {
            victim = Topan.Network.GetPlayerByID(vID);
        }

        if ((killerIsBot) ? killerBot == null : killer == null || (victimIsBot) ? victimBot == null : victim == null)
        {
            return;
        }

        byte killerTeam = (killerIsBot) ? killerBot.team : (byte)killer.GetPlayerData("team");
        byte victimTeam = (victimIsBot) ? victimBot.team : (byte)victim.GetPlayerData("team");

        string klrColor  = (killerTeam == 0) ? "[D75216]" : "[407499]";
        string vctmColor = (victimTeam == 0) ? "[D75216]" : "[407499]";

        if (!GeneralVariables.gameModeHasTeams)
        {
            klrColor  = (kID == Topan.Network.player.id) ? "[B05C25]" : "[707070]";
            vctmColor = (vID == Topan.Network.player.id) ? "[B05C25]" : "[707070]";
        }

        CombatantInfo kInfo = (killerIsBot) ? killerBot.botInfo : (CombatantInfo)killer.GetInitialData("dat");
        CombatantInfo vInfo = (victimIsBot) ? victimBot.botInfo : (CombatantInfo)victim.GetInitialData("dat");

        bool suicide = (kID == vID);

        if (suicide)
        {
            kfManager.AddToFeed(vctmColor + vInfo.username + "[-]", "himself", -1);

            if (GeneralVariables.spawnController != null && inSpawnScreen)
            {
                GeneralVariables.spawnController.AddToFeed(vctmColor + vInfo.username + "[-]", "himself", -1);
            }
        }
        else
        {
            kfManager.AddToFeed(klrColor + kInfo.username + "[-]", vctmColor + vInfo.username + "[-]", wepIndex);

            if (GeneralVariables.spawnController != null && inSpawnScreen)
            {
                GeneralVariables.spawnController.AddToFeed(klrColor + kInfo.username + "[-]", vctmColor + vInfo.username + "[-]", wepIndex);
            }
        }
    }