private GUIButton ShowFaction(Vector2 offSet, EFaction faction)
        {
            GameObject      go       = new GameObject();
            CSpriteRenderer sr       = new CSpriteRenderer("SlotNameBar");
            Texture2D       texture1 = SpriteContainer.Instance.Sprite["SlotNameBar"];
            Texture2D       texture2 = SpriteContainer.Instance.Sprite["SlotNameBar"];
            GUIButton       btn      = new GUIButton(sr, texture1, texture2, Color.White, Color.YellowGreen);

            go.AddComponent <CSpriteRenderer>(sr);
            go.AddComponent <GUIButton>(btn);

            float   newScale = SpriteContainer.Instance.NormalFont.MeasureString(faction.ToString()).X / texture1.Width;
            Vector2 scale    = new Vector2(newScale, 0.8f);

            sr.LayerDepth = 0.03f;
            sr.SetOrigin(EOriginPosition.TopLeft);
            go.MyParent           = actionBarFactionAndTeam;
            go.Transform.Scale    = new Vector2(0.5f, 0.5f) * GraphicsSetting.Instance.ScreenScale * scale;
            go.Transform.Position = go.MyParent.Transform.Position + new Vector2(offSet.X * GraphicsSetting.Instance.ScreenScale.X, -go.MyParent.GetComponent <CSpriteRenderer>().Sprite.Height *go.MyParent.Transform.Scale.Y + (offSet.Y * GraphicsSetting.Instance.ScreenScale.Y));

            TextToSlotBar(faction.ToString(), new Vector2(sr.Sprite.Width, sr.Sprite.Height) * go.Transform.Scale, go, EOriginPosition.Mid, new Vector2(0, 0));

            myScene.Instantiate(go);

            btn.OnClick += () => { placeTile.Faction = faction; placeTile.GameObjectTileMouse.IsActive = false; SetColorOnFaction(btn); };

            return(btn);
        }
        public void OnSpawned(SpawnContext spawnContext, ProjectilesPool projectilesPool)
        {
            contactFilter = new ContactFilter2D()
            {
                useLayerMask = true,
                useTriggers  = true
            };

            faction = spawnContext.Instigator.Faction;

            meshRenderer.SetEmission(spawnContext.Color);

            //manage parameters regarding instigator faction
            switch (spawnContext.Instigator.Faction)
            {
            case EFaction.Player:
                contactFilter.layerMask = Layers.Bit.Enemy | Layers.Bit.EnemyProjectile;
                this.gameObject.layer   = Layers.Int.PlayerProjectile;
                break;

            case EFaction.Enemy:
                contactFilter.layerMask = Layers.Bit.Player | Layers.Bit.PlayerProjectile;
                this.gameObject.layer   = Layers.Int.EnemyProjectile;
                break;

            default:
                break;
            }
            attachedPool = projectilesPool;
            context      = spawnContext;

            transform.rotation = Quaternion.LookRotation(Vector3.forward, context.Direction);
            transform.position = context.Position;
        }
        public void TestUnit(EFaction factions, EUnitType unitType, int number)
        {
            GameObject      go       = new GameObject();
            CSpriteRenderer sp       = new CSpriteRenderer(SpriteContainer.Instance.Pixel);
            CAnimator       animator = new CAnimator();
            CUnit           unit     = new CUnit(ETeam.Team01, unitType, factions);
            CMove           move     = new CMove();

            go.AddComponent <CUnit>(unit);
            go.AddComponent <CMove>(move);
            go.AddComponent <CSpriteRenderer>(sp);
            go.AddComponent <CAnimator>(animator);

            go.Transform.Position -= new Microsoft.Xna.Framework.Vector2(650 - 150 * number, 0);
            Instantiate(go);
        }
        public void ReadSave(SaveState state)
        {
            Name               = state.ReadIndexedString();
            Description        = state.ReadIndexedString();
            LateJoinersAllowed = state.Reader.ReadBooleanStrict();

            // RoundSettings
            int roundSettingCount = state.ReadVariableLengthInt();

            RoundSettings = new Array <Ref <GameRoundSettings> >(roundSettingCount);

            for (int i = 0; i < roundSettingCount; i++)
            {
                string settingName = state.ReadIndexedString();

                // TODO: Object/resource name is "World" with type "GameRoundSettings" - lookups not currently implemented
                RoundSettings.Add(new Ref <GameRoundSettings>());
            }

            // MissionSetting
            int missionSettingCount = state.ReadVariableLengthInt();

            MissionSetting = new Array <MissionSettings>(missionSettingCount);

            for (int i = 0; i < missionSettingCount; i++)
            {
                var settings = new MissionSettings();
                settings.ReadSave(state);

                MissionSetting.Add(settings);
            }

            // Let's serialize this entire structure even though reflection is available. Brilliant.
            EndGameWhenWinnerDecided = state.Reader.ReadBooleanStrict();
            SpawnLives                 = state.ReadVariableLengthInt();
            UseSpawnWaves              = state.Reader.ReadBooleanStrict();
            DeathCamTime               = state.Reader.ReadSingle();
            RespawnTimer               = state.ReadVariableLengthInt();
            GracePeriod                = state.ReadVariableLengthInt();
            InactivityKickTime         = state.ReadVariableLengthInt();
            TimeBetweenMissions        = state.ReadVariableLengthInt();
            BodycountQuota             = state.ReadVariableLengthInt();
            CaHCaptureTime             = state.ReadVariableLengthInt();
            CaCCaptureTimeInner        = state.ReadVariableLengthInt();
            CaCCaptureTimeMiddle       = state.ReadVariableLengthInt();
            CaCCaptureTimeOuter        = state.ReadVariableLengthInt();
            CaSCaptureTime             = state.ReadVariableLengthInt();
            ExplosivePlacing           = state.ReadVariableLengthInt();
            ExplosiveDefusing          = state.ReadVariableLengthInt();
            ExplosiveDetonationTime    = state.ReadVariableLengthInt();
            FriendlyFireEnabled        = state.Reader.ReadBooleanStrict();
            CloseCombatSettings        = (ECloseCombatSettings)state.Reader.ReadByte();
            ShowEnemiesOnRadar         = state.Reader.ReadBooleanStrict();
            ShowAmmoCounter            = state.Reader.ReadBooleanStrict();
            AmmoSettings               = (EAmmoSettings)state.Reader.ReadByte();
            MaxPlayerCount             = state.ReadVariableLengthInt();
            MaxPlayerSpectatorCount    = state.ReadVariableLengthInt();
            MaxAdminSpectatorCount     = state.ReadVariableLengthInt();
            MinClientCount             = state.ReadVariableLengthInt();
            ClansMinPlayerCount        = state.ReadVariableLengthInt();
            ClansForfeitTimer          = state.Reader.ReadInt32();// !
            PlayerHealthSettings       = (EPlayerHealthSettings)state.Reader.ReadByte();
            HealthRegenerationSettings = (EHealthRegenerationSettings)state.Reader.ReadByte();
            MaxBotCount                = state.ReadVariableLengthInt();
            BotFaction                 = (EFaction)state.Reader.ReadByte();
            SplitScreenGame            = state.Reader.ReadBooleanStrict();
            GameMode               = (EGameMode)state.Reader.ReadByte();
            BotzoneGame            = state.Reader.ReadBooleanStrict();
            PracticeGame           = state.Reader.ReadBooleanStrict();
            ClanGame               = state.Reader.ReadBooleanStrict();
            IsCustomGame           = state.Reader.ReadBooleanStrict();
            IsAdminCreatedGame     = state.Reader.ReadBooleanStrict();
            CampaignScoringEnabled = state.Reader.ReadBooleanStrict();
            _ = state.Reader.ReadByte();// !

            PlaylistPassword = state.ReadIndexedString();
            SelectedChallengeRequirements = state.ReadIndexedString();

            // CareerSettings
            int careerSettingCount = state.ReadVariableLengthInt();

            CareerSettings = new Array <ECareerSettings>(careerSettingCount);

            for (int i = 0; i < careerSettingCount; i++)
            {
                CareerSettings.Add((ECareerSettings)state.Reader.ReadByte());
            }

            DisabledUnlockResources = new Array <String>();
            DisabledUnlockResources.DeserializeStateObject(state);

            TrackedLeaderboardStats = new Array <String>();
            TrackedLeaderboardStats.DeserializeStateObject(state);

            CombatHonorsEnabled  = state.Reader.ReadBooleanStrict();
            Creator              = state.ReadIndexedString();
            CreatedTimestamp     = state.Reader.ReadInt64();
            TeamVoiceChat        = state.Reader.ReadBooleanStrict();
            PartiesAllowed       = state.Reader.ReadBooleanStrict();
            PreGameLobbyWaitTime = state.ReadVariableLengthInt();
        }
Beispiel #5
0
        public GameObject Create(string type, EFaction faction, ETeam team)
        {
            EBuildingType buildingType = (EBuildingType)Enum.Parse(typeof(EBuildingType), type);

            GameObject      go       = new GameObject();
            CSpriteRenderer sr       = new CSpriteRenderer(SpriteContainer.Instance.SpriteSheet["GrayTent"]);
            CBuilding       building = new CBuilding(buildingType, faction, team);
            CStats          stats    = new CStats();

            sr.LayerDepth         = 0.3f;
            sr.OriginPositionEnum = EOriginPosition.TopLeft;
            sr.OffSet             = new Vector2(-1 * 128 / 2, -3 * 128 / 2);
            go.Transform.Scale   *= 0.5f;

            go.AddComponent <CSpriteRenderer>(sr);
            go.AddComponent <CBuilding>(building);
            go.AddComponent <CStats>(stats);

            switch (buildingType)
            {
            case EBuildingType.TownHall:
                break;

            case EBuildingType.ArcheryRange:
                break;

            case EBuildingType.Blacksmith:
                break;

            case EBuildingType.Tower:
                break;

            case EBuildingType.Barracks:
                break;

            case EBuildingType.GatheringStation:
                break;

            case EBuildingType.Field:
                sr.OffSet = new Vector2(0 * 128 / 2, 0 * 128 / 2);
                sr.SetSprite(SpriteContainer.Instance.TileSprite.Wheatfield);
                break;

            default:
                break;
            }

            if (buildingType != EBuildingType.Field)
            {
                switch (team)
                {
                case ETeam.Team01:
                    sr.Color = Color.Red;
                    break;

                case ETeam.Team02:
                    sr.Color = Color.Blue;
                    break;

                case ETeam.Team03:
                    sr.Color = Color.Green;
                    break;

                case ETeam.Team04:
                    sr.Color = Color.Yellow;
                    break;

                case ETeam.Team05:
                    break;

                case ETeam.Team06:
                    break;

                case ETeam.Team07:
                    break;

                case ETeam.Team08:
                    break;

                default:
                    break;
                }
            }

            return(go);
        }
        public GameObject Create(string type, EFaction faction, ETeam team)
        {
            // Main GameObject
            GameObject      go            = new GameObject();
            CSpriteRenderer sr            = new CSpriteRenderer(SpriteContainer.Instance.Pixel);
            CAnimator       animator      = new CAnimator();
            CUnit           unit          = new CUnit(team, (EUnitType)Enum.Parse(typeof(EUnitType), type), faction);
            CMove           move          = new CMove();
            CStats          stats         = new CStats();
            CAstar          astar         = new CAstar(unit);
            CSelectable     canBeSelected = new CSelectable();
            CShadow         shadow        = new CShadow();

            go.AddComponent <CUnit>(unit);
            go.AddComponent <CMove>(move);
            go.AddComponent <CStats>(stats);
            go.AddComponent <CShadow>(shadow);
            go.AddComponent <CSpriteRenderer>(sr);
            go.AddComponent <CAnimator>(animator);
            go.AddComponent <CSelectable>(canBeSelected);
            go.AddComponent <CAstar>(astar);

            switch (team)
            {
            case ETeam.Team01:
                sr.Color = Color.LightPink;
                break;

            case ETeam.Team02:
                sr.Color = Color.LightBlue;
                break;

            case ETeam.Team03:
                sr.Color = Color.LightGreen;
                break;

            case ETeam.Team04:
                sr.Color = Color.Yellow;
                break;

            case ETeam.Team05:
                break;

            case ETeam.Team06:
                break;

            case ETeam.Team07:
                break;

            case ETeam.Team08:
                break;

            default:
                break;
            }

            sr.LayerDepth       = 0.3f;
            sr.OffSet           = new Vector2(-0.75f * 128, -0.9f * 128);
            go.Transform.Scale *= 1.0f;

            return(go);
        }