Beispiel #1
0
    public Interactable GetInteractableEntityByTypeAndId(BoatEntityType type, int id)
    {
        Interactable interactable = null;

        if (this.boatEntitiesByType.ContainsKey(type))
        {
            if (this.boatEntitiesByType[type].ContainsKey(id))
            {
                interactable = this.boatEntitiesByType[type][id] as Interactable;
            }
        }

        return(interactable);
    }
Beispiel #2
0
    public static void SpawnProjectile(Packet packet)
    {
        int            id             = packet.ReadInt();
        ProjectileType type           = (ProjectileType)packet.ReadInt();
        int            boatId         = packet.ReadInt();
        int            boatEntityId   = packet.ReadInt();
        BoatEntityType boatEntityType = (BoatEntityType)packet.ReadInt();


        Boat               boat               = BoatManager.Boats[boatId];
        BoatEntity         boatEntity         = boat.boatEntitiesByType[boatEntityType][boatEntityId];
        ProjectileLauncher projectileLauncher = boatEntity as ProjectileLauncher;
        Transform          launcher           = projectileLauncher != null?projectileLauncher.GetLauncher() : boatEntity.transform;

        Projectile projectile = GameObject.Instantiate <Projectile>(ProjectileByType[(ProjectileType)type], launcher.position, launcher.rotation);

        projectile.TargetPosition = launcher.position;
        Projectiles.Add(id, projectile);
    }
    public static void RecieveBoatsFromServer(Packet packet)
    {
        Debug.Log("Recieving Boats");
        int boatCount = packet.ReadInt();

        for (int i = 1; i <= boatCount; i++)
        {
            int        id  = packet.ReadInt();
            Vector3    pos = packet.ReadVector3();
            Quaternion rot = packet.ReadQuaternion();

            Boat boat = GameObject.Instantiate <Boat>(instance.boatPrefab, pos, rot);
            boat.Init(id);

            int boatEntityTypeCount = packet.ReadInt();

            for (int ii = 1; ii <= boatEntityTypeCount; ii++)
            {
                BoatEntityType boatEntityType    = (BoatEntityType)packet.ReadInt();
                int            entityOfTypeCount = packet.ReadInt();

                for (int iii = 1; iii <= entityOfTypeCount; iii++)
                {
                    int        entiyId       = packet.ReadInt();
                    Vector3    localPosition = packet.ReadVector3();
                    Quaternion localRotation = packet.ReadQuaternion();
                    Vector3    localScale    = packet.ReadVector3();

                    BoatEntity entity = Instantiate <BoatEntity>(BoatEntityByType[boatEntityType], boat.transform);
                    entity.id = entiyId;
                    entity.transform.localPosition = localPosition;
                    entity.transform.localRotation = localRotation;
                    entity.transform.localScale    = localScale;
                    entity.ReadDataFromPacket(packet);

                    boat.boatEntitiesByType[boatEntityType][entity.id] = entity;
                }
            }

            Boats.Add(boat.id, boat);
        }
    }
    public static void IneractRequest(int fromClient, Packet packet)
    {
        int clientId = packet.ReadInt();

        if (fromClient != clientId)
        {
            Debug.Log($"Player (ID: {fromClient}) has assumed the wrong client ID ({clientId})!");
            return;
        }

        int             id              = packet.ReadInt();
        BoatEntityType  boatEntityType  = (BoatEntityType)packet.ReadInt();
        InteractionType interactionType = (InteractionType)packet.ReadInt();

        Pirate       pirate       = PirateManager.instance.Pirates[clientId];
        Interactable interactable = pirate.boat.GetInteractableEntityByTypeAndId(boatEntityType, id);

        if (interactable != null)
        {
            pirate.BeginInteractWith(interactable, interactionType);
        }
    }
    public static void HandleBoatTransformUpdate(Packet packet)
    {
        int        id  = packet.ReadInt();
        Vector3    pos = packet.ReadVector3();
        Quaternion rot = packet.ReadQuaternion();

        if (!BoatManager.Boats.ContainsKey(id))
        {
            return;
        }

        Boat boat = BoatManager.Boats[id];

        boat.TargetPosition     = pos;
        boat.transform.rotation = rot;

        int boatEntityTypeCount = packet.ReadInt();

        for (int ii = 1; ii <= boatEntityTypeCount; ii++)
        {
            BoatEntityType boatEntityType    = (BoatEntityType)packet.ReadInt();
            int            entityOfTypeCount = packet.ReadInt();

            for (int iii = 1; iii <= entityOfTypeCount; iii++)
            {
                int        entiyyId      = packet.ReadInt();
                Vector3    localPosition = packet.ReadVector3();
                Quaternion localRotation = packet.ReadQuaternion();
                Vector3    localScale    = packet.ReadVector3();

                BoatEntity entity = boat.boatEntitiesByType[boatEntityType][entiyyId];
                entity.transform.localPosition = localPosition;
                entity.transform.localRotation = localRotation;
                entity.transform.localScale    = localScale;
                entity.ReadDataFromPacket(packet);
            }
        }
    }