Esempio n. 1
0
 public override void OnServerOnlineSceneLoaded()
 {
     base.OnServerOnlineSceneLoaded();
     this.InvokeInstanceDevExtMethods("OnServerOnlineSceneLoaded");
     RegisterEntities();
     // Spawn monsters
     MonsterSpawnArea[] monsterSpawnAreas = FindObjectsOfType <MonsterSpawnArea>();
     foreach (MonsterSpawnArea monsterSpawnArea in monsterSpawnAreas)
     {
         monsterSpawnArea.SpawnAll();
     }
     // Spawn Warp Portals
     if (GameInstance.MapWarpPortals.Count > 0)
     {
         List <WarpPortal> mapWarpPortals;
         if (GameInstance.MapWarpPortals.TryGetValue(CurrentMapInfo.Id, out mapWarpPortals))
         {
             foreach (WarpPortal warpPortal in mapWarpPortals)
             {
                 WarpPortalEntity warpPortalPrefab = warpPortal.entityPrefab != null ? warpPortal.entityPrefab : gameInstance.warpPortalEntityPrefab;
                 if (warpPortalPrefab != null)
                 {
                     GameObject       spawnObj         = Instantiate(warpPortalPrefab.gameObject, warpPortal.position, Quaternion.identity);
                     WarpPortalEntity warpPortalEntity = spawnObj.GetComponent <WarpPortalEntity>();
                     warpPortalEntity.type     = warpPortal.warpPortalType;
                     warpPortalEntity.mapInfo  = warpPortal.warpToMapInfo;
                     warpPortalEntity.position = warpPortal.warpToPosition;
                     Assets.NetworkSpawn(spawnObj);
                 }
             }
         }
     }
     // Spawn Npcs
     if (GameInstance.MapNpcs.Count > 0)
     {
         List <Npc> mapNpcs;
         if (GameInstance.MapNpcs.TryGetValue(CurrentMapInfo.Id, out mapNpcs))
         {
             foreach (Npc npc in mapNpcs)
             {
                 NpcEntity npcPrefab = npc.entityPrefab;
                 if (npcPrefab != null)
                 {
                     GameObject spawnObj  = Instantiate(npcPrefab.gameObject, npc.position, Quaternion.Euler(npc.rotation));
                     NpcEntity  npcEntity = spawnObj.GetComponent <NpcEntity>();
                     npcEntity.StartDialog = npc.startDialog;
                     npcEntity.Title       = npc.title;
                     Assets.NetworkSpawn(spawnObj);
                 }
             }
         }
     }
     // If it's server (not host) spawn simple camera controller
     if (!IsClient && GameInstance.Singleton.serverCharacterPrefab != null)
     {
         Instantiate(GameInstance.Singleton.serverCharacterPrefab);
     }
 }
Esempio n. 2
0
        protected void UpdateInput()
        {
            if (GenericUtils.IsFocusInputField())
            {
                return;
            }

            if (PlayerCharacterEntity.IsDead())
            {
                return;
            }

            // If it's building something, don't allow to activate NPC/Warp/Pickup Item
            if (!ConstructingBuildingEntity)
            {
                // Activate nearby npcs / players / activable buildings
                if (InputManager.GetButtonDown("Activate"))
                {
                    targetPlayer = null;
                    if (ActivatableEntityDetector.players.Count > 0)
                    {
                        targetPlayer = ActivatableEntityDetector.players[0];
                    }
                    targetNpc = null;
                    if (ActivatableEntityDetector.npcs.Count > 0)
                    {
                        targetNpc = ActivatableEntityDetector.npcs[0];
                    }
                    targetBuilding = null;
                    if (ActivatableEntityDetector.buildings.Count > 0)
                    {
                        targetBuilding = ActivatableEntityDetector.buildings[0];
                    }
                    targetVehicle = null;
                    if (ActivatableEntityDetector.vehicles.Count > 0)
                    {
                        targetVehicle = ActivatableEntityDetector.vehicles[0];
                    }
                    targetWarpPortal = null;
                    if (ActivatableEntityDetector.warpPortals.Count > 0)
                    {
                        targetWarpPortal = ActivatableEntityDetector.warpPortals[0];
                    }
                    targetItemsContainer = null;
                    if (ItemDropEntityDetector.itemsContainers.Count > 0)
                    {
                        targetItemsContainer = ItemDropEntityDetector.itemsContainers[0];
                    }
                    // Priority Player -> Npc -> Buildings
                    if (targetPlayer && CacheUISceneGameplay)
                    {
                        // Show dealing, invitation menu
                        SelectedEntity = targetPlayer;
                        CacheUISceneGameplay.SetActivePlayerCharacter(targetPlayer);
                    }
                    else if (targetNpc)
                    {
                        // Talk to NPC
                        SelectedEntity = targetNpc;
                        PlayerCharacterEntity.CallServerNpcActivate(targetNpc.ObjectId);
                    }
                    else if (targetBuilding)
                    {
                        // Use building
                        SelectedEntity = targetBuilding;
                        ActivateBuilding(targetBuilding);
                    }
                    else if (targetVehicle)
                    {
                        // Enter vehicle
                        PlayerCharacterEntity.CallServerEnterVehicle(targetVehicle.ObjectId);
                    }
                    else if (targetWarpPortal)
                    {
                        // Enter warp, For some warp portals that `warpImmediatelyWhenEnter` is FALSE
                        PlayerCharacterEntity.CallServerEnterWarp(targetWarpPortal.ObjectId);
                    }
                    else if (targetItemsContainer)
                    {
                        // Show items
                        ShowItemsContainerDialog(targetItemsContainer);
                    }
                }
                // Pick up nearby items
                if (InputManager.GetButtonDown("PickUpItem"))
                {
                    targetItemDrop = null;
                    if (ItemDropEntityDetector.itemDrops.Count > 0)
                    {
                        targetItemDrop = ItemDropEntityDetector.itemDrops[0];
                    }
                    if (targetItemDrop != null)
                    {
                        PlayerCharacterEntity.CallServerPickupItem(targetItemDrop.ObjectId);
                    }
                }
                // Reload
                if (InputManager.GetButtonDown("Reload"))
                {
                    // Reload ammo when press the button
                    ReloadAmmo();
                }
                if (InputManager.GetButtonDown("ExitVehicle"))
                {
                    // Exit vehicle
                    PlayerCharacterEntity.CallServerExitVehicle();
                }
                if (InputManager.GetButtonDown("SwitchEquipWeaponSet"))
                {
                    // Switch equip weapon set
                    GameInstance.ClientInventoryHandlers.RequestSwitchEquipWeaponSet(new RequestSwitchEquipWeaponSetMessage()
                    {
                        equipWeaponSet = (byte)(PlayerCharacterEntity.EquipWeaponSet + 1),
                    }, ClientInventoryActions.ResponseSwitchEquipWeaponSet);
                }
                if (InputManager.GetButtonDown("Sprint"))
                {
                    // Toggles sprint state
                    isSprinting = !isSprinting;
                }
                // Auto reload
                if (PlayerCharacterEntity.EquipWeapons.rightHand.IsAmmoEmpty() ||
                    PlayerCharacterEntity.EquipWeapons.leftHand.IsAmmoEmpty())
                {
                    // Reload ammo when empty and not press any keys
                    ReloadAmmo();
                }
            }

            UpdateLookInput();
            UpdateWASDInput();
            PlayerCharacterEntity.SetExtraMovement(isSprinting ? ExtraMovementState.IsSprinting : ExtraMovementState.None);
        }