Example #1
0
    public static GameObject MakeStructure(ThingTypes thingType, bool isBlueprint)
    {
        if (!ThingFactory.IsBlueprint(thingType))
        {
            Debug.LogError("StructureFactory.MakeStructure got a non-blueprint thingType: " + thingType);
            return(null);
        }

        GameObject          prefab    = GetStructurePrefab(thingType);
        GameObject          structure = Instantiate(prefab) as GameObject;
        StructureController sc        = structure.GetComponent <StructureController>();

        if (isBlueprint)
        {
            sc.SetupBlueprint();
        }
        else
        {
            sc.SetupRealStructure();
        }

        if (isBlueprint)
        {
            ParentChildFunctions.SetMaterialOfChildren(structure, Blueprint.GetBlueprintMaterial());
            ParentChildFunctions.SetCollisionForChildren(structure, false);
        }
        else if (!sc.HasColliders())
        {
            //real structures with no colliders get mesh colliders
            ParentChildFunctions.SetCollisionForChildren(structure, !isBlueprint);
        }

        return(structure);
    }
Example #2
0
 // Use this for initialization
 void Start()
 {
     Player             = GetComponent <Player>().Info;
     inputController    = GetComponent <StructureController>();
     completionAction   = () => ProductionAction();
     cancellationAction = () => CancellationAction();
 }
Example #3
0
 private StructureController GetStructureController()
 {
     if (structureController == null)
     {
         structureController = gameObject.GetComponent <StructureController>();
     }
     return(structureController);
 }
 void Awake()
 {
     myTran     = transform;
     parentTran = transform.parent;
     if (parentTran != null)
     {
         parentCtrl = parentTran.GetComponent <StructureController>();
     }
     nowHp = maxHp;
 }
Example #5
0
 public static void CloseActiveStructure()
 {
     _structurePanel.SetActive(false);
     if (activeStructure != null)
     {
         activeStructure.OnGuiClose();
         activeStructure = null;
     }
     Debug.Log("Closing structure");
 }
Example #6
0
    public static void OpenStructure(StructureController structure)
    {
        if (activeStructure != null)
        {
            CloseActiveStructure();
        }

        activeStructure = structure;
        RefreshGui();
        _structurePanel.SetActive(true);
    }
Example #7
0
 public void MakeIfConstructed()
 {
     //this turns the blueprint into a real structure. removes nodes, deletes itself, and activates structure.
     if (IsConstructed())
     {
         GameObject          realStructure       = StructureFactory.MakeStructure(thing.thingType, false);
         StructureController structureController = realStructure.GetComponent <StructureController> ();
         realStructure.transform.position = blueprintStructure.transform.position;
         realStructure.transform.rotation = blueprintStructure.transform.rotation;
         Destroy(gameObject);
     }
 }
Example #8
0
 public DocumentService()
 {
     _test               = new TestController(this);
     _factory            = new FactoryController(this);
     _document           = new DocumentController(this);
     _page               = new PageController(this);
     _structure          = new StructureController(this);
     _statusJobConverter = new StatusJobConverterController(this);
     _annotations        = new AnnotationsController(this);
     _cache              = new CacheController(this);
     _compare            = new CompareController(this);
 }
Example #9
0
    public void SetConstructionProject(StructureController project)
    {
        if (project == null)
        {
            isConstructing = false;
            return;
        }

        currentProject = project;
        SetWaypoint(currentProject);
        isConstructing = true;
    }
Example #10
0
        public ProfilePage(ServiceContainer container, string profileId) : base(container)
        {
            structureController = Container.Get <StructureController>("structure");
            bookmarkController  = Container.Get <BookmarkController>("bookmark");
            authController      = Container.Get <AuthController>("auth");
            profileApi          = Container.Get <ProfileApi>("api/profile");
            imageApi            = Container.Get <ImageApi>("api/image");
            adventureApi        = Container.Get <AdventureApi>("api/adventure");

            this.profileId = profileId;

            InitializeComponent();
        }
Example #11
0
        public ProfileEditPage(ServiceContainer container, string profileId) : base(container)
        {
            structureController = Container.Get <StructureController>("structure");
            profileApi          = Container.Get <IProfileApi>("api/profile");
            imageApi            = Container.Get <ImageApi>("api/image");

            InitializeComponent();

            viewModel      = new ProfileEditViewModel();
            BindingContext = viewModel;

            cts = new CancellationTokenSource();
            profileApi.Get(profileId).Subscribe(SetModel, cts.Token);
        }
    void SpawnCurrentStructure()
    {
        Vector3    position = new Vector3(_currentTile.position.x, _currentTile.position.y + 0.4f, _currentTile.position.z);
        Quaternion rotation = Quaternion.Euler(new Vector3(0, 180, 0));

        GameObject          structure = Instantiate(spawnedObject, position, rotation) as GameObject;
        StructureController comp      = structure.GetComponent <StructureController>();

        comp.cost       = cost;
        comp.hasUpMoved = true;
        _currentTile.GetComponent <Gridtile>().occupied = true;

        Gamesystem.wealth -= cost;
    }
Example #13
0
    private void WindowFunction(int id)
    {
        int  row      = 0;
        Rect viewRect = new Rect(0, 0, scrollRect.width, StructureController.GetStructureControllers().Count *rowHeight);

        scrollPosition = GUI.BeginScrollView(scrollRect, scrollPosition, viewRect);
        foreach (StructureController structureController in StructureController.GetStructureControllers())
        {
            DrawStructureRow(structureController, row * rowHeight);
            row++;
        }
        GUI.EndScrollView();

        GUI.DragWindow();
    }
Example #14
0
 private void SetDomeStructureController()
 {
     if (domeStructureController == null || !domeStructureController.IsUsableByAWG())
     {
         foreach (RaycastHit raycastHit in Physics.RaycastAll(transform.position, Vector3.up, 100))
         {
             StructureController sc = StructureController.GetStructureControllerFromChild(raycastHit.transform.gameObject);
             if (sc != null && sc.IsUsableByAWG())
             {
                 domeStructureController = sc;
                 return;
             }
         }
     }
 }
Example #15
0
    protected void LoadCurrentProject(int entityId)
    {
        if (entityId < 0)
        {
            return;
        }

        try
        {
            currentProject = (StructureController)GameManager.activeInstance.GetGameEntityById(entityId);
        }
        catch
        {
            Debug.Log(string.Format("Failed to load current Project"));
        }
    }
Example #16
0
 public static bool ColonyHasAtLeastThisMuch(ResourceTypes resourceType, float thisMuch)
 {
     if (thisMuch < 0)
     {
         Debug.LogError("ColonyHasAtLeastThisMuch got a negative value. " + thisMuch);
     }
     foreach (StructureController sc in StructureController.GetStructureControllers())
     {
         thisMuch -= sc.structureInfo.reserves[resourceType];
         if (thisMuch < 0)
         {
             return(true);
         }
     }
     return(false);
 }
Example #17
0
        private int Upgrade(StructureController controller, int amount)
        {
            int used = amount;

            if (controller.ProgressTotal <= (amount + controller.Progress))
            {
                controller.Level++;
                controller.ProgressTotal    = controller.GetProgressTotal(controller.Level + 1);
                controller.TicksToDowngrade = controller.GetTicksToDowngrade(controller.Level + 1);
                controller.Progress         = 0;
            }
            else
            {
                controller.Progress        += amount;
                controller.TicksToDowngrade = controller.GetTicksToDowngrade(controller.Level + 1);
            }

            return(used);
        }
Example #18
0
    void CheckForEnemiesInRadius()
    {
        int hits = 0;

        Collider[] objectsInRange = Physics.OverlapSphere(transform.position, damageRadius);

        foreach (Collider col in objectsInRange)
        {
            if (col.gameObject.tag == "Structure")
            {
                StructureController structure = col.gameObject.GetComponent <StructureController>();

                if (structure != null)
                {
                    structure.TakeDamage(damage);
                }
            }
            else if (col.gameObject.tag == "Turret")
            {
            }
            else if (col.gameObject.tag == "Enemy")
            {
                EnemyBulletController enemy = col.GetComponent <EnemyBulletController>();

                if (enemy != null)
                {
                    float proximity    = (transform.position - enemy.transform.position).magnitude;
                    float effect       = 1 - (proximity / damageRadius);
                    float damageAmount = (damage * effect);
                    damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage);

                    enemy.DealDamage(damage);

                    hits++;
                }
            }
        }

        if (hits > 0)
        {
            ExpireMe();
        }
    }
Example #19
0
    private static void AddResources(ResourceTypes resourceType, float positiveAmount)
    {
        float amountRemaining = positiveAmount;

        foreach (StructureController sc in StructureController.GetStructureControllers())
        {
            if (!sc.structureInfo.HasSpaceLeft(resourceType))
            {
                continue;
            }

            float freeSpace   = sc.structureInfo.GetSpaceLeft(resourceType);
            float givenAmount = amountRemaining > freeSpace ? freeSpace : amountRemaining;
            amountRemaining -= givenAmount;
            sc.structureInfo.ChangeResourceAmount(resourceType, givenAmount);
        }

        GetResources()[resourceType] += positiveAmount - amountRemaining;
    }
    void CheckForEnemiesInRadius()
    {
        Collider[] objectsInRange = Physics.OverlapSphere(transform.position, controller.damageRadius);

        float damage = controller.damage;

        foreach (Collider col in objectsInRange)
        {
            if (col.gameObject.tag == "Structure")
            {
                StructureController structure = col.gameObject.GetComponent <StructureController>();
                Debug.DrawLine(transform.position, col.gameObject.transform.position, Color.red, 2.0f);

                if (structure != null)
                {
                    float proximity = (transform.position - structure.transform.position).magnitude;
                    float effect    = 1 - (proximity / controller.damageRadius);

                    float damageAmount = (damage * effect);
                    damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage);

                    structure.TakeDamage(damageAmount);
                }
            }
            else if (col.gameObject.tag == "Turret")
            {
                TurretBarrelController turret = col.gameObject.GetComponent <TurretBarrelController>();
                Debug.DrawLine(transform.position, col.gameObject.transform.position, Color.red, 2.0f);

                if (turret != null)
                {
                    float proximity = (transform.position - turret.transform.position).magnitude;
                    float effect    = 1 - (proximity / controller.damageRadius);

                    float damageAmount = (damage * effect);
                    damageAmount = Mathf.Clamp(damageAmount, 1.0f, damage);

                    turret.TakeDamage(damageAmount);
                }
            }
        }
    }
    void Start()
    {
        toggle_labels = new Text[num_toggles];
        toggles       = new Toggle[num_toggles];
        for (int i = 0; i < num_toggles; i++)
        {
            toggles[i]       = GameObject.Find(i + "").GetComponent <Toggle>();
            toggle_labels[i] = GameObject.Find(i + "Label").GetComponent <Text>();
        }
        ship = GameObject.Find("Ship").GetComponent <StructureController>();
        placement_overlay = GameObject.Find("PlacementOverlay");
        toggle_group      = GameObject.Find("LeftCanvas").GetComponent <ToggleGroup>();
        right_input       = GameObject.Find("RightInput").GetComponent <InputField>();
        interpreter       = GameObject.Find("RightViewContent").GetComponent <Text>();
        left_title        = GameObject.Find("LeftTitle").GetComponent <Text>();
        camera_controller = GameObject.Find("Main Camera").GetComponent <CameraController>();
        component_content = GameObject.Find("LeftViewContent");
        component_content.GetComponent <Text>().text = default_content;

        Deselect();
    }
    public void SetSlotStructure(int _slot, StructureController _structure)
    {
        Assert.IsFalse(_slot < 0 || _slot >= segments);

        if (structures[_slot])
        {
            structures[_slot].BeforeRemovedFromPlanet();
            Destroy(structures[_slot].gameObject);
        }

        structures[_slot] = _structure;

        if (structures[_slot])
        {
            structures[_slot].transform.SetParent(planetMeshController.slotSockets[_slot]);
            structures[_slot].transform.localPosition = Vector3.zero;
            structures[_slot].transform.localRotation = Quaternion.identity;
            structures[_slot].transform.localScale    = Vector3.one;
            _structure.planet = this;
            structures[_slot].AfterAddedToPlanet();
        }
    }
    //Structure強化実行
    protected override void BulletCustomExe(BulletController bulletCtrl, int customSystem, float effectValue)
    {
        StructureController structureCtrl = bulletCtrl.transform.GetComponent <StructureController>();

        switch (customSystem)
        {
        case CUSTOM_SYSTEM_STRUCTURE_HP:
            structureCtrl.CustomHp((int)effectValue);
            break;

        case CUSTOM_SYSTEM_REFLECTION:
            structureCtrl.CustomReflection(effectValue == 1);
            break;

        case CUSTOM_SYSTEM_CHANGE_BREAK_EFFECT:
            structureCtrl.CustomChangeBreakEffect(addObject);
            break;

        default:
            base.BulletCustomExe(bulletCtrl, customSystem, effectValue);
            break;
        }
    }
Example #24
0
    private void DrawStructureRow(StructureController structureController, float yPosition)
    {
        bigCellRect.y  = yPosition;
        cellRect.y     = yPosition;
        tinyCellRect.y = yPosition;

        float x = 0;

        cellRect.x = x;
        PicNameStatusReusable pnr = new PicNameStatusReusable(structureController.matchingThing.name, structureController.matchingThing.iconTexture);

        pnr.Draw(cellRect, structureController.GetStatusTexture());

        x += cellRect.width;
        tinyCellRect.x = x;
        pnr            = new PicNameStatusReusable(structureController.GetStatusLabel(), structureController.GetStatusTexture());
        pnr.Draw(tinyCellRect);

        x         += tinyCellRect.width;
        cellRect.x = x;
        IconGroupReusable igr = structureController.GetIconGroup();

        igr.Draw(cellRect);
    }
Example #25
0
    private static void TakeResources(ResourceTypes resourceType, float negativeAmount)
    {
        float debtRemaining = Mathf.Abs(negativeAmount);

        foreach (StructureController sc in StructureController.GetStructureControllers())
        {
            float reserve = sc.structureInfo.reserves[resourceType];
            if (reserve < 0.01)
            {
                continue;
            }

            float takenAmount = debtRemaining;
            if (debtRemaining > reserve)
            {
                takenAmount = reserve;
            }

            debtRemaining -= takenAmount;
            sc.structureInfo.ChangeResourceAmount(resourceType, -takenAmount);
        }

        GetResources()[resourceType] += negativeAmount;
    }
Example #26
0
    private void RallyPointButtonHandler(StructureController structure, int leftEdge, int topEdge, int width, int height)
    {
        Texture2D rallyPointIcon = structure.rallyPointIcon;
        bool buttonPressed = GUI.Button(new Rect(leftEdge, topEdge, width, height), rallyPointIcon);
        if (buttonPressed == false)
        {
            return;
        }

        if (activeCursorState != CursorState.rallyPoint && previousCursorState != CursorState.rallyPoint)
        {
            SetCursorState(CursorState.rallyPoint);
        }
        else
        {
            SetCursorState(CursorState.panRight);
            SetCursorState(CursorState.select);
        }
    }
Example #27
0
    public void SpawnUnit(string unitName, Vector3 spawnPoint, Vector3 rallyPoint, Quaternion startingOrientation, StructureController spawner)
    {
        GameObject allUnits = transform.Find(PlayerProperties.UNITS).gameObject;
        if (allUnits == null)
        {
            return;
        }

        GameObject unitToSpawn = (GameObject)Instantiate(GameManager.activeInstance.GetUnitPrefab(unitName), spawnPoint, startingOrientation);
        unitToSpawn.transform.parent = allUnits.transform;
        Debug.Log(string.Format("Spawned {0} for player {1}", unitName, username));

        if (rallyPoint == ResourceManager.invalidPoint)
        {
            return;
        }

        UnitController controller = unitToSpawn.GetComponent<UnitController>();
        if (controller == null)
        {
            return;
        }

        controller.SetSpawner(spawner);

        if (spawnPoint == rallyPoint)
        {
            return;
        }

        controller.SetWaypoint(rallyPoint);
    }
Example #28
0
    public void SpawnStructure(string structureName, Vector3 buildPoint, UnitController builder, Rect playingArea)
    {
        GameObject structureToSpawn = (GameObject)Instantiate(GameManager.activeInstance.GetStructurePrefab(structureName),
            buildPoint, new Quaternion());

        constructionSite = structureToSpawn.GetComponent<StructureController>();
        if (constructionSite != null)
        {
            constructor = builder;
            isSettingConstructionPoint = true;
            constructionSite.SetTransparencyMaterial(notAllowedMaterial, true);
            constructionSite.SetColliders(false);
            constructionSite.playingArea = playingArea;
        }
        else
        {
            Destroy(structureToSpawn);
        }
    }
Example #29
0
 public void CancelConstruction()
 {
     isSettingConstructionPoint = false;
     Destroy(constructionSite.gameObject);
     constructionSite = null;
     constructor = null;
 }
Example #30
0
    private void DrawBuildQueue(StructureController selectedStructure)
    {
        if (selectedStructure == null)
        {
            return;
        }

        string[] buildQueue = selectedStructure.GetBuildQueueEntries();
        float buildPercentage = selectedStructure.GetBuildCompletionPercentage();

        for (int i = 0; i < buildQueue.Length; i++)
        {
            float topEdge = i * BUILD_IMAGE_HEIGHT - (i + 1) * BUILD_IMAGE_PADDING;
            Rect buildArea = new Rect(BUILD_IMAGE_PADDING, topEdge, BUILD_IMAGE_WIDTH, BUILD_IMAGE_HEIGHT);
            string unitName = buildQueue[i];
            Texture2D unitIcon = GameManager.activeInstance.GetBuildIcon(unitName);
            GUI.DrawTexture(buildArea, unitIcon);
            GUI.DrawTexture(buildArea, buildFrame);
            topEdge += BUILD_IMAGE_PADDING;
            float width = BUILD_IMAGE_WIDTH - 2 * BUILD_IMAGE_PADDING;
            float height = BUILD_IMAGE_HEIGHT - 2 * BUILD_IMAGE_PADDING;
            if (i == 0)
            {
                // Shrink the build mask on the time currently being built to give an idea of progress
                topEdge += height * buildPercentage;
                height *= (1 - buildPercentage);
            }
            int leftEdge = 2 * BUILD_IMAGE_PADDING;
            GUI.DrawTexture(new Rect(leftEdge, topEdge, width, height), buildMask);
        }
    }
Example #31
0
 protected override void Awake()
 {
     base.Awake();
     structureController = new StructureController(this, structureConfig, structureData);
 }
Example #32
0
 public override void SetSpawner(StructureController spawner)
 {
     base.SetSpawner(spawner);
     SetConstructionProject(spawner);
 }
Example #33
0
    private void DrawStandardStructureOptions(StructureController structure)
    {
        if (player == null)
        {
            return;
        }
        if (player.selectedEntity == null)
        {
            return;
        }
        if (structure == null)
        {
            return;
        }

        GUIStyle smallButtons = new GUIStyle();
        smallButtons.hover.background = smallButtonHover;
        smallButtons.active.background = smallButtonClick;
        GUI.skin.button = smallButtons;

        int leftEdge = BUILD_IMAGE_WIDTH + SCROLL_BAR_WIDTH + BUTTON_PADDING;
        int topEdge = buildAreaHeight - BUILD_IMAGE_HEIGHT / 2;
        int width = BUILD_IMAGE_WIDTH / 2;
        int height = BUILD_IMAGE_HEIGHT / 2;

        bool hasSpawnPoint = structure.HasValidSpawnPoint();
        if (hasSpawnPoint == false)
        {
            return;
        }

        SellButtonHandler(structure, leftEdge, topEdge, width, height);
        RallyPointButtonHandler(structure, leftEdge, topEdge, width, height);
    }
Example #34
0
 public CreepUpgrade(Creep crp, StructureController ctrl)
 {
     Creep      = crp;
     Controller = ctrl;
 }
    //ダメージ処理
    protected void AddDamage(GameObject hitObj)
    {
        //ダメージ系処理は所有者のみ行う
        if (photonView.isMine)
        {
            //AttackRate計算
            float dmg = damage;
            if (ownerStatus != null)
            {
                dmg *= (ownerStatus.attackRate / 100);
            }

            if (hitObj.CompareTag("Player") || hitObj.tag == "Target")
            {
                isHit = true;

                if (dmg > 0 || statusChangeCtrl != null)
                {
                    //プレイヤーステータス
                    PlayerStatus status = GetHitObjStatus(hitObj);

                    if (status.IsReflection())
                    {
                        Reflection();
                        return;
                    }

                    //ダメージ
                    float addDmg = AddDamageProccess(status, dmg);

                    //デバフ
                    AddDebuff(status);

                    //スタック
                    if (stuckTime > 0)
                    {
                        status.AttackInterfareMove(stuckTime);
                    }

                    //ノックバック
                    if (knockBackRate != 0 && addDmg > 0)
                    {
                        TargetKnockBack(hitObj.transform, knockBackRate);
                    }
                }
            }
            else if (hitObj.CompareTag(Common.CO.TAG_STRUCTURE))
            {
                isHit = true;

                //ダメージ倍率計算
                if (myTran.tag == Common.CO.TAG_BULLET_EXTRA)
                {
                    dmg *= Common.CO.EXTRA_BULLET_BREAK_RATE;
                }
                StructureController structCtrl = hitObj.GetComponent <StructureController>();
                if (structCtrl != null)
                {
                    structCtrl.AddDamage((int)dmg);
                }
            }
            else if (hitObj.CompareTag(Common.CO.TAG_FLOOR))
            {
                isHit = true;
            }
        }
    }
 void Start()
 {
     _gSystem = GameObject.FindObjectOfType<Gridsystem>();
     _sController = gameObject.GetComponent<StructureController>();
 }
Example #37
0
    protected void LoadResourceStore(int entityId)
    {
        if (entityId < 0)
        {
            return;
        }

        try
        {
            resourceStore = (StructureController)GameManager.activeInstance.GetGameEntityById(entityId);
        }
        catch
        {
            Debug.Log(string.Format("Failed to load Resource Store"));
        }
    }
 void Awake()
 {
     planetMeshController = GetComponentInChildren <PlanetMeshController>();
     structures           = new StructureController[segments];
     resourceStorage      = new Dictionary <ResourceType, ResourceStorage>();
 }
Example #39
0
 public override void SetSpawner(StructureController spawner)
 {
     base.SetSpawner(spawner);
     SetDepository(spawner);
 }
Example #40
0
 public void SetDepository(StructureController depository)
 {
     resourceStore = depository;
 }
Example #41
0
    void Update()
    {
        // INPUT
        Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        bool    hoveringPlanet     = false;

        foreach (PlanetController planet in m_planets)
        {
            int slot = planet.GetSlotAtWorldPosition(mouseWorldPosition);
            if (slot >= 0)
            {
                hoveringPlanet = true;
                SetCurrentlyHoveredPlanet(planet, slot);
                break;
            }
        }
        if (!hoveringPlanet)
        {
            SetCurrentlyHoveredPlanet(null);
        }

        if (m_currentlyHoveredPlanet)
        {
            if (m_currentlyHoveredPlanet.structures[m_currentlyHoveredSlot] == null)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    StructureController structure = Instantiate(cityPrefab);
                    m_currentlyHoveredPlanet.SetSlotStructure(m_currentlyHoveredSlot, structure);
                }
                else if (Input.GetMouseButtonDown(1))
                {
                    StructureController structure = Instantiate(farmPrefab);
                    m_currentlyHoveredPlanet.SetSlotStructure(m_currentlyHoveredSlot, structure);
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(2))
                {
                    m_currentlyHoveredPlanet.SetSlotStructure(m_currentlyHoveredSlot, null);
                }
            }
        }

        // CYCLES
        if (cycleDuration > 0.0f)
        {
            deltaCycles   = (Time.deltaTime * cycleTimeMultiplier) / cycleDuration;
            m_cycleTimer -= deltaCycles;
            totalCycles  += deltaCycles;
            while (m_cycleTimer <= 0.0f)
            {
                m_cycleTimer += 1.0f;

                foreach (PlanetController planet in m_planets)
                {
                    planet.OnCycle();
                }
            }
        }
    }
Example #42
0
        private static RoomObject DeepCopyRoomObject(RoomObject obj, Room room, Game game, Player user)
        {
            RoomObject copy = null;

            if (obj != null)
            {
                switch (obj.GetType().Name)
                {
                case "StructureSpawn":
                    var spawn = (StructureSpawn)obj;
                    copy = new StructureSpawn()
                    {
                        Game = game,
                        My   = spawn.Owner != null && spawn.Owner.ID == user.ID,
                        Pos  = room.GetPositionAt(spawn.Pos.X, spawn.Pos.Y),
                        Room = room,

                        Energy         = spawn.Energy,
                        EnergyCapacity = spawn.EnergyCapacity,
                        HitPoints      = spawn.HitPoints,
                        HitPointsMax   = spawn.HitPointsMax,
                        ID             = spawn.ID,
                        IsActive       = spawn.IsActive,
                        Name           = spawn.Name,
                        Owner          = spawn.Owner,
                        Spawning       = spawn.Spawning,
                        Type           = spawn.Type,
                        Memory         = new Dictionary <string, object>(),
                    };

                    game.Memory.Add(copy.ID, ((StructureSpawn)copy).Memory);

                    if (spawn.Memory != null)
                    {
                        foreach (string key in spawn.Memory.Keys)
                        {
                            ((StructureSpawn)copy).Memory.Add(key, room.Memory[key]);
                        }

                        ((StructureSpawn)copy).Memory["#"] = 2;
                    }
                    break;

                case "StructureController":
                    var controller = (StructureController)obj;
                    copy = new StructureController()
                    {
                        Game = game,
                        Room = room,

                        Owner = controller.Owner,
                        My    = controller.Owner != null && controller.Owner.ID == user.ID,

                        HitPoints    = controller.HitPoints,
                        HitPointsMax = controller.HitPointsMax,
                        ID           = controller.ID,
                        IsActive     = controller.IsActive,
                        Pos          = controller.Pos,
                        Type         = controller.Type,

                        Progress         = controller.Progress,
                        ProgressTotal    = controller.ProgressTotal,
                        Level            = controller.Level,
                        TicksToDowngrade = controller.TicksToDowngrade,
                    };
                    break;

                case "Source":
                    var source = (Source)obj;
                    copy = new Source()
                    {
                        Game = game,
                        Room = room,

                        Energy            = source.Energy,
                        EnergyCapacity    = source.EnergyCapacity,
                        ID                = source.ID,
                        Pos               = source.Pos,
                        TicksToRegenerate = source.TicksToRegenerate,
                    };
                    break;

                case "Creep":
                    var creep = (Creep)obj;

                    // TODO: Player-defined child class

                    copy = new Creep()
                    {
                        Game = game,
                        My   = (creep.Owner.ID == user.ID),
                        Room = room,

                        Body               = creep.Body,
                        Fatigue            = creep.Fatigue,
                        HitPoints          = creep.HitPoints,
                        HitPointsMax       = creep.HitPointsMax,
                        ID                 = creep.ID,
                        Name               = creep.Name,
                        NotifyWhenAttacked = creep.NotifyWhenAttacked,
                        Owner              = creep.Owner,
                        Pos                = creep.Pos,
                        Saying             = creep.Saying,
                        Spawning           = creep.Spawning,
                        TicksToLive        = creep.TicksToLive,

                        Memory    = new Dictionary <string, object>(),
                        _carrying = new Dictionary <ResourceTypes, int>(),
                    };

                    game.Memory.Add(copy.ID, ((Creep)copy).Memory);

                    foreach (string key in creep.Memory.Keys)
                    {
                        ((Creep)copy).Memory.Add(key, creep.Memory[key]);
                    }

                    ((Creep)copy).Memory["#"] = 2;

                    foreach (var key in creep._carrying.Keys)
                    {
                        ((Creep)copy)._carrying.Add(key, creep._carrying[key]);
                    }
                    break;

                default:
                    string type = obj.GetType().Name;
                    break;
                }
            }

            return(copy);
        }
Example #43
0
 public virtual void SetSpawner(StructureController spawner)
 {
 }
 void Start()
 {
     _gSystem     = GameObject.FindObjectOfType <Gridsystem>();
     _sController = gameObject.GetComponent <StructureController>();
 }
Example #45
0
    private void SellButtonHandler(StructureController structure, int leftEdge, int topEdge, int width, int height)
    {
        Texture2D sellIcon = structure.sellIcon;
        leftEdge += width + BUTTON_PADDING;

        bool buttonPressed = GUI.Button(new Rect(leftEdge, topEdge, width, height), sellIcon);
        if (buttonPressed == false)
        {
            return;
        }

        structure.Sell();
    }