private void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }

        else if (instance != this)
        {
            Debug.LogError("Tried to create another instance of " + GetType() + ". Destroying.");
            Destroy(gameObject);
        }

        ScenarioSetup.RegisterWorldController(this);
    }
Exemple #2
0
        /// <summary>
        /// Scans for all scenarios defined in the class and runs them
        /// </summary>
        protected internal virtual void executeScenarioSetups(Type clazz)
        {
            IDictionary <string, Scenario> scenarios = new Dictionary <string, Scenario>();

            foreach (System.Reflection.MethodInfo method in clazz.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance))
            {
                DescribesScenario scenarioAnnotation = method.getAnnotation(typeof(DescribesScenario));
                if (scenarioAnnotation != null)
                {
                    Scenario scenario = new Scenario();

                    scenario.Name = createScenarioName(clazz, scenarioAnnotation.value());
                    ExtendsScenario extendedScenarioAnnotation = method.getAnnotation(typeof(ExtendsScenario));
                    if (extendedScenarioAnnotation != null)
                    {
                        scenario.ExtendedScenario = createScenarioName(clazz, extendedScenarioAnnotation.value());
                    }

                    try
                    {
                        ScenarioSetup setup = (ScenarioSetup)method.invoke(null, new object[0]);
                        scenario.Setup = setup;
                    }
                    catch (Exception e)
                    {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                        throw new Exception("Could not invoke method " + clazz.FullName + "#" + method.Name + " specifying scenarios " + scenario.Name, e);
                    }

                    Times timesAnnotation = method.getAnnotation(typeof(Times));
                    if (timesAnnotation != null)
                    {
                        scenario.Times = timesAnnotation.value();
                    }

                    scenarios[scenario.Name] = scenario;
                }
            }

            foreach (Scenario scenario in scenarios.Values)
            {
                setupScenario(scenarios, scenario);
            }
        }
    // [Server] enforced with inline code check
    public GameObject SpawnPlayer(NetworkConnection conn, string nick)
    {
        if (!IsServerOrDemo())
        {
            return(null);
        }

        //Debug.LogFormat("Spawning Player with connectionID {0} and nick {1}", conn.connectionId, nick);

        var playerPos = worldBuilder.GetNextPlayerPosition();

        GameObject playerGO = Instantiate(playerPrefab, new Vector3(playerPos.x, 0, playerPos.z), Quaternion.identity);

        if (worldParent != null)
        {
            playerGO.transform.parent = worldParent;
        }

        PlayerController player = playerGO.GetComponent <PlayerController>();

        player.Initialize(conn.connectionId.ToString(), nick, playerColorManager.GetNextColor());

        if (Settings.Debug_PlayerAsAI)
        {
            playerGO.AddComponent <AndreAI>();
        }

        /* NOTE: Always set properties before spawning object, if not there will be a delay before all clients get the values. */
        if (NetworkServer.active)
        {
            NetworkServer.AddPlayerForConnection(conn, playerGO, 0); // playerControllerId is used if multiple players is using one connection
        }
        else
        {
            Debug.LogWarning("NetworkServer not active, it should be when spawning player");
        }

        SpawnObject(cityPrefab, playerPos.x, playerPos.z, player, conn);

        ScenarioSetup.Run(NetworkPanel.instance.GetSelectedScenarioChoice(), conn, player);

        return(playerGO);
    }
    public GameObject SpawnAI(string nick)
    {
        Debug.Log("Spawning AI: " + nick);

        var aiPos = worldBuilder.GetNextPlayerPosition();

        GameObject aiPlayerGO = SpawnObject(playerPrefab, aiPos.x, aiPos.z);

        PlayerController player = aiPlayerGO.GetComponent <PlayerController>();

        player.Initialize(nick.Replace(" ", "_"), nick, playerColorManager.GetNextColor());

        SpawnObject(cityPrefab, aiPos.x, aiPos.z, player);

        ScenarioSetup.Run(NetworkPanel.instance.GetSelectedScenarioChoice(), null, player); // A bit dirty atm, sending in the hosting players connection for AIs for spawning.

        aiPlayerGO.AddComponent <AndreAI>();

        return(aiPlayerGO);
    }
Exemple #5
0
 public virtual Scenario perform(ScenarioSetup setup)
 {
     this.setup = setup;
     return(this);
 }