Example #1
0
    public void readFromNbt(NbtCompound tag)
    {
        this.resources = tag.getIntArray("resources");

        foreach (NbtCompound compound in tag.getList("mapObjects"))
        {
            int id = compound.getInt("id");
            RegisteredObject registeredObject = Registry.getObjectFromRegistry(id);
            if (registeredObject != null)
            {
                SpawnInstructions <MapObject> instructions = this.spawnEntity <MapObject>(registeredObject, compound);
                instructions.getObj().map    = this;
                instructions.getObj().nbtTag = compound;
            }
            else
            {
                Logger.logError("MapObject with an unknown ID of " + id + " was found!  Ignoring!");
            }
        }

        // Now that every MapObject is loaded and their Guid is set, preform the normal reading from nbt.
        foreach (MapObject obj in this.mapObjects)
        {
            obj.readFromNbt(obj.nbtTag);
        }
    }
Example #2
0
    protected override void preformTask(float deltaTime)
    {
        if (this.trainingQueue.Count != 0)
        {
            if (this.isTeamFull())
            {
                return;
            }

            this.trainingProgress += deltaTime;

            UnitBase nextInQueue = this.trainingQueue[0].getPrefab().GetComponent <UnitBase>();
            if (this.trainingProgress >= 0)  // nextInQueue.getData().getProductionTime()) {
            {
                Vector2 v = Random.insideUnitCircle * 2f;
                float   i = 1.5f;
                v.x += (v.x < 0 ? -i : i);
                v.y += (v.x < 0 ? -i : i);

                Vector3          pos    = this.transform.position + new Vector3(v.x, 0, v.y);
                RegisteredObject regObj = this.trainingQueue[0];
                this.trainingQueue.RemoveAt(0);

                SpawnInstructions <SidedEntity> instructions = this.map.spawnEntity <SidedEntity>(
                    regObj,
                    pos,
                    Quaternion.Euler(0, Random.Range(0, 359), 0));
                instructions.getObj().setTeam(this.getTeam());
                instructions.spawn();

                this.trainingProgress = 0;
            }
        }
    }
    public void spawnEntity(MessageSpawnEntity msg)
    {
        SpawnInstructions <SidedEntity> instructions = this.map.spawnEntity <SidedEntity>(
            Registry.getObjectFromRegistry(msg.entityId),
            msg.position,
            msg.rotation);

        instructions.getObj().setTeam(msg.getTeam());
        instructions.spawn();
    }
Example #4
0
    // Use this for initialization
    void Start()
    {
        Time.timeScale = 1;
        pauseObjects   = GameObject.FindGameObjectsWithTag("ShowOnPause");
        hidePaused();

        Button resumeBtn = resumePlay.GetComponent <Button>();
        Button quitBtn   = quit.GetComponent <Button>();
        Button pause     = pauseButton.GetComponent <Button> ();

        spawnInstructions = GetComponent <SpawnInstructions>();

        resumeBtn.onClick.AddListener(ResumeOnClick);
        quitBtn.onClick.AddListener(QuitOnClick);
        pause.onClick.AddListener(pauseMenu);
    }
Example #5
0
    // Use this for initialization
    void Start()
    {
        spawner = gameObject.AddComponent <SpawnInstructions> ();

        Button confirmBtn = confirm.GetComponent <Button> ();

        confirmBtn.onClick.AddListener(HandleConfirm);

        Button exitBtn = exit.GetComponent <Button> ();

        exitBtn.onClick.AddListener(Exit);

        Button repeatBtn = repeat.GetComponent <Button> ();

        repeat.onClick.AddListener(Repeat);

        spawner.commandPrefab = commandPrefab;
    }
Example #6
0
    // Use this for initialization
    void Start()
    {
        floormask = LayerMask.GetMask("Floor");

        Player = GameObject.FindGameObjectWithTag("Player");
        // playerRigidbody = GetComponent<Rigidbody>();

        //Button btn = playButton.GetComponent<Button>();
        btnInstance   = GetComponent <UIButtonClick>();
        whileInstance = GetComponent <WhileCommand>();
        spawn         = GetComponent <SpawnInstructions>();
        //btn.onClick.AddListener(TaskOnClick);

        //store original position of player
        //originalPos = player.transform.position;
        isRotating     = false;
        targetAngle    = Player.transform.eulerAngles.y;
        targetRotation = Quaternion.AngleAxis(targetAngle, Vector3.up);
    }
    public void constructBuilding(MessageConstructBuilding msg)
    {
        // Create the new building GameObject and set it's team.
        SpawnInstructions <BuildingBase> instructions = this.map.spawnEntity <BuildingBase>(
            Registry.getObjectFromRegistry(msg.entityId),
            new Vector3(msg.position.x, 0, msg.position.z),
            Quaternion.identity);
        BuildingBase newBuilding = instructions.getObj();
        Team         team        = Team.getTeamFromId(msg.teamId);

        newBuilding.setTeam(team);

        // Remove resources from the builder's team.
        this.map.reduceResources(team, newBuilding.getData().getCost());

        // Set the buildings health and send the builder to build it.
        BuildingData bd = newBuilding.getData();

        if (bd.isInstantBuild())
        {
            newBuilding.setHealth(bd.getMaxHealth());
        }
        else
        {
            newBuilding.setHealth(1);
            UnitBuilder builder = map.findMapObjectFromGuid <UnitBuilder>(msg.builderGuid);
            builder.setTask(new TaskConstructBuilding(builder, newBuilding));
            builder.unitStats.buildingsBuilt.increase();
        }

        if (newBuilding is BuildingBridge)
        {
        }

        instructions.spawn();
    }