示例#1
0
    public void OnConnectedToSession(int uid)
    {
        GD.Print("This should only get called once");
        //If this is the start of the application, disconnect the signal from root.
        if (uid == -1)
        {
            GetNode("/root").Disconnect("ready", this, nameof(OnConnectedToSession));
        }
        else
        {
            EasyInstancer.NetworkID = uid;
        }

        //Manually replace because the default seems to do it async
        //and we need to do this synchronously.
        GetNode("/root/GameRoot/GameWorld").Free();
        var gameWorld = EasyInstancer.Instance <Node>("res://GameWorld.tscn");

        GetNode("/root/GameRoot").AddChild(gameWorld);

        Users = gameWorld.GetNode("Users");
        UserProvider provider = UserProvider.Factory.Instance();

        Users.AddChild(provider);
        LocalUser.Subscribe(provider);
    }
    public override void _Ready()
    {
        mainMenu = (MainMenu)GetNode("MainMenu/MainMenu");
        Input.SetMouseMode(Input.MouseMode.Visible);

        InventoryMenu = EasyInstancer.Instance <InventoryMenu>("res://BasicScenes/GUI/2.5D UI/Inventory/InventoryMenu.tscn");

        //We are the last ones in line, since we only care about Esc key.
        //Any other system that uses it gets it first.
        Claims.Claims.Add("ui_cancel");
        InputPriorityServer.Base.Subscribe(this, BaseRouter.gameManagement);
    }
示例#3
0
    //Default code for firing a projectile.
    //Unlikely anyone will need to modify this very much.
    //But you can!
    public virtual void Fire()
    {
        string projectileScene = source.DequeueMunition();

        if (!(projectileScene is null))
        {
            Vector3 velocity = Muzzle.GlobalTransform.basis.Xform(-Vector3.Left) * muzzleVelocity;

            ProjectileProvider p = EasyInstancer.Instance <ProjectileProvider>(projectileScene);
            Projectiles.AddChild(p);
            p.Rpc("Init", Muzzle.GlobalTransform.origin, velocity);
        }
    }
示例#4
0
    //Override and call base Instance to do actual deserialization.
    public virtual IReplicable Instance(SceneTree tree, bool newName = false)
    {
        IReplicable instance = (IReplicable)EasyInstancer.Instance <Node>(ScenePath);

        if (newName)
        {
            instance.rMember.GenName();
        }
        else
        {
            instance.Name = Name;
        }
        tree.Root.GetNode(Parent).AddChild((Node)instance);
        ((ISaveable)instance).ApplyData(Data);
        return(instance);
    }
示例#5
0
    public void ReplicateRPC(string parent, string name, string scenePath)
    {
        GD.Print("Replicating: ", parent, "; ", name, "; ", scenePath);
        GD.Print("Peer ID: ", GetTree().GetRpcSenderId());

        var parentNode = GetNode(parent);

        if (parentNode is null)
        {
            GD.Print("parent node path :<", parent, "> invalid");
            return;
        }

        string childPath = parent + "/" + name;
        var    childNode = (IReplicable)GetNodeOrNull(childPath);

        if (childNode is null)
        {
            //If it doesn't exist yet, then just replicate it.
            //Easiest case to handle.
            childNode = (IReplicable)EasyInstancer.Instance <Node>(scenePath);

            childNode.Name = name;
            var sender = GetTree().GetRpcSenderId();
            childNode.SetNetworkMaster(sender);
            parentNode.AddChild((Node)childNode);
            if (listeners.ContainsKey(childPath))
            {
                foreach (NotifyReplicated listener in listeners[childPath])
                {
                    listener((Node)childNode);
                }
                listeners.Remove(childPath);
            }
        }
        else
        {
            GD.PrintErr("Replication Error: Node path collision/ non-master call");
            GD.PrintErr(childPath);
            //purely for debugging. Shouldn't happen.
            //Don't know how to deal with this in production.
        }
    }