Esempio n. 1
0
 public Inventory SearchInventoryContains(User user, Type itemType)
 {
     foreach (ConnectorObject conv in inputConveyors)
     {
         // If the connected input don't exist, destroy the connector
         if (WorldObjectManager.GetFromID(conv.Input.ObjectID) == null)
         {
             conv.CleanDestroy();
             break;
         }
         if (conv.Operating == false)
         {
             continue;
         }
         // If the owner of the input object is authorized to interract with the conv
         if (Utils.IsAuthorizedToInteract(conv, user))
         {
             // If the owner of the connector can interract with the output
             if (Utils.IsAuthorizedToInteract(conv.Input, conv.OwnerUser))
             {
                 foreach (var item in conv.InvInput.Stacks)
                 {
                     if (item.Quantity > 0)
                     {
                         if (item.Item.Type == itemType)
                         {
                             return(conv.InvInput);
                         }
                     }
                 }
             }
         }
     }
     return(null);
 }
Esempio n. 2
0
 public static void AirPollutionGenerators(User user)
 {
     for (var i = 0; i < 50; i++)
     {
         WorldObjectManager.ForceAdd(ServiceHolder <IWorldObjectManager> .Obj.GetTypeFromName("AirPollutionGeneratorObject"), user, World.GetTopGroundPos(World.GetRandomLandPos().XZ) + Vector3i.Up, Quaternion.Identity);
     }
 }
Esempio n. 3
0
        public override Result OnAreaValid(Player player, Vector3i position, Quaternion rotation)
        {
            Deed deed = PropertyManager.FindNearbyDeedOrCreate(player.User, position.XZ);

            foreach (var plot in WorldObject.GetOccupiedPropertyPositions(typeof(StarterCampObject), position, rotation))
            {
                PropertyManager.Claim(deed.Id, player.User, player.User.Inventory, plot);
            }

            var camp      = WorldObjectManager.TryToAdd(typeof(CampsiteObject), player.User, position, rotation, false);
            var stockpile = WorldObjectManager.TryToAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false);

            player.User.OnWorldObjectPlaced.Invoke(camp);
            player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent());
            player.User.Markers.Add(stockpile.Position3i + Vector3i.Up, stockpile.UILinkContent());
            var storage   = camp.GetComponent <PublicStorageComponent>();
            var changeSet = new InventoryChangeSet(storage.Inventory);

            PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x =>
            {
                changeSet.AddItems(x.Key, x.Value, storage.Inventory);
            });
            changeSet.Apply();
            return(Result.Succeeded);
        }
Esempio n. 4
0
 private void Start()
 {
     vMM = GetComponent <VisitedMapManager>();
     wOM = GetComponent <WorldObjectManager>();
     rT  = new RenderTexture(Data.HeightMapWidth, Data.HeightMapHeight, 16, RenderTextureFormat.ARGB1555);
     rT.Create();
 }
Esempio n. 5
0
    private IEnumerator PostScores()
    {
        GameObject hand = GameObject.Find(pm.name);
        float      x    = hand.GetComponent <Transform>().position.x;
        float      y    = hand.GetComponent <Transform>().position.y;
        float      z    = hand.GetComponent <Transform>().position.z;

        string final  = highscoreURL + pm.name + "'&Pos_X=" + x + "&Pos_Y=" + y + "&Pos_Z=" + z;
        var    hs_get = new UnityWebRequest(final);

        hs_get.downloadHandler = new DownloadHandlerBuffer();
        yield return(hs_get.SendWebRequest());

        if (hs_get.error != null)
        {
            print("There was an error getting the high score: " + hs_get.error);
        }
        else
        {
            CmdSendMessage("Left the game");

            if (isServer)
            {
                WorldObjectManager nm2 = FindObjectOfType <WorldObjectManager>();
                nm2._dirty.Clear();
                nm.StopHost();
                nm.StopServer();
            }
            else
            {
                nm.StopClient();
            }
            SceneManager.LoadScene("Menu");
        }
    }
Esempio n. 6
0
    public void Init()
    {
        worldData    = WorldDataGenerator.GenerateEmptyWorld(worldWidth, worldLength, worldHeight);
        worldObjects = new WorldObjectContainer(worldWidth, worldLength, worldHeight, this.transform, worldData);

        WorldObjectManager.InstantiateAllObjects(worldData, worldObjects);
    }
 public static void PolluteAir(User user)
 {
     for (int i = 0; i < 50; i++)
     {
         WorldObjectManager.TryToAdd(WorldObjectManager.GetTypeFromName("APGenObject"), user, World.GetTopPos(World.GetRandomLandPos().XZ) + Vector3i.Up, Quaternion.Identity);
     }
 }
Esempio n. 8
0
        public override void OnClientConnect(QNetworkConnection connection)         // Called on the client when connecting to a server
        {
            DebugLog.DebugWrite("OnClientConnect", MessageType.Info);
            base.OnClientConnect(connection);

            QSBEventManager.Init();

            gameObject.AddComponent <RespawnOnDeath>();

            if (QSBSceneManager.IsInUniverse)
            {
                WorldObjectManager.Rebuild(QSBSceneManager.CurrentScene);
            }

            var specificType = QNetworkServer.active ? QSBPatchTypes.OnServerClientConnect : QSBPatchTypes.OnNonServerClientConnect;

            QSBPatchManager.DoPatchType(specificType);
            QSBPatchManager.DoPatchType(QSBPatchTypes.OnClientConnect);

            _lobby.CanEditName = false;

            OnNetworkManagerReady?.SafeInvoke();
            IsReady = true;

            QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null,
                                        () => QSBEventManager.FireEvent(EventNames.QSBPlayerJoin, _lobby.PlayerName));

            if (!QSBCore.IsServer)
            {
                QSBCore.UnityEvents.RunWhen(() => QSBEventManager.Ready && PlayerTransformSync.LocalInstance != null,
                                            () => QSBEventManager.FireEvent(EventNames.QSBPlayerStatesRequest));
            }

            _everConnected = true;
        }
Esempio n. 9
0
        public ConnectorObject GetFirstValidOutput(WorldObject inputObject, Type transportItemType)
        {
            // User is the owner of the input object (I.E hopper)
            User user = inputObject.OwnerUser;

            foreach (ConnectorObject conv in outputConveyors)
            {
                if (WorldObjectManager.GetFromID(conv.Output.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Output, conv.OwnerUser))
                    {
                        if (conv.filter.CanAccept(transportItemType) && Utils.VerifyInventoryPlace(conv.InvOutput, transportItemType))
                        {
                            return(conv);
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 10
0
        public InventoryCollection GetAllOutputInventory(User user, Type itemToPlace = null)
        {
            List <Inventory> invList = new List <Inventory>();

            foreach (ConnectorObject conv in outputConveyors)
            {
                // If the connected output don't exist, destroy the connector
                if (WorldObjectManager.GetFromID(conv.Output.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Output, conv.OwnerUser))
                    {
                        if (itemToPlace != null && conv.filter.CanAccept(itemToPlace) == false)
                        {
                            continue;
                        }
                        invList.Add(conv.InvOutput);
                    }
                }
            }
            return(new InventoryCollection(invList));
        }
Esempio n. 11
0
 private static void ResetRoomRequirements(User user)
 {
     foreach (var obj in WorldObjectManager.GetOwnedBy(user))
     {
         var requirements = obj.GetComponent <RoomRequirementsComponent>();
         requirements?.MarkDirty();
     }
 }
Esempio n. 12
0
 public void SetObject(int x, int z, int y, GameObject obj)
 {
     if (worldObjects[x, z, y] != null)
     {
         WorldObjectManager.DestroyObject(this, x, z, y);
     }
     worldObjects[x, z, y] = obj;
 }
Esempio n. 13
0
 public void ModifyWorldData(int x, int z, int y, Tile.ID id)
 {
     if (x < worldData.GetWidth() && z < worldData.GetLength() && y < worldData.GetHeight() && x >= 0 && z >= 0 && y >= 0)
     {
         worldData.SetData(x, z, y, id);
         WorldObjectManager.ReplaceObject(worldObjects, x, z, y, id);
     }
 }
        public static string SellMessage(DateTime timestamp, SellAction a)
        {
            string     currency = WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <CreditComponent>().CurrencyName;
            TradeOffer offer    = (from TradeOffer o in WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <StoreComponent>().SellOffers()
                                   where o.Stack.Item.FriendlyName == a.ItemTypeName
                                   select o).FirstOrDefault();

            return($"Sell(timestamp={timestamp:u}, worldtime={a.TimeSeconds}, item={a.ItemTypeName}, price={offer.Price}, currency={currency}, user={a.Username})\n");
        }
        public static void RestoreWorldObjectBlock(Type type, Vector3i position, IWorldEditBlockData blockData, UserSession session)
        {
            if (blockData == null)
            {
                return;
            }
            WorldEditWorldObjectBlockData worldObjectBlockData = (WorldEditWorldObjectBlockData)blockData;

            ClearWorldObjectPlace(worldObjectBlockData.WorldObjectType, position, worldObjectBlockData.Rotation, session);

            WorldObject worldObject = null;

            try { worldObject = WorldObjectManager.ForceAdd(worldObjectBlockData.WorldObjectType, session.User, position, worldObjectBlockData.Rotation, true); }
            catch (Exception e)
            {
                Log.WriteException(e);
            }
            if (worldObject == null)
            {
                Log.WriteErrorLineLoc($"Unable spawn WorldObject {worldObjectBlockData.WorldObjectType} at {position}");
                return;
            }
            if (worldObject.HasComponent <StorageComponent>() && worldObjectBlockData.Components.ContainsKey(typeof(StorageComponent)))
            {
                StorageComponent      storageComponent = worldObject.GetComponent <StorageComponent>();
                List <InventoryStack> inventoryStacks;
                object component = worldObjectBlockData.Components[typeof(StorageComponent)];
                if (component is JArray)
                {
                    JArray jArray = (JArray)component;
                    inventoryStacks = jArray.ToObject <List <InventoryStack> >();
                }
                else
                {
                    inventoryStacks = (List <InventoryStack>)component;
                }

                foreach (InventoryStack stack in inventoryStacks)
                {
                    if (stack.ItemType == null)
                    {
                        continue;
                    }
                    Result result = storageComponent.Inventory.TryAddItems(stack.ItemType, stack.Quantity);
                    if (result.Failed)
                    {
                        session.Player.ErrorLocStr(result.Message.Trim());
                        try { storageComponent.Inventory.AddItems(stack.GetItemStack()); } catch (InvalidOperationException) { /*Already show error to user*/ }
                    }
                }
            }
            if (worldObject.HasComponent <CustomTextComponent>() && worldObjectBlockData.Components.ContainsKey(typeof(CustomTextComponent)))
            {
                CustomTextComponent textComponent = worldObject.GetComponent <CustomTextComponent>();
                textComponent.TextData.Text = (string)worldObjectBlockData.Components[typeof(CustomTextComponent)];
            }
        }
Esempio n. 16
0
        private void OpenChoppingWindow()
        {
            var player = EntityManager.Get <IEntity>(Game.GameSession.Player.ObjectId);

            if (WorldObjectManager.ContainsWorldObject <ILocation>(player.CurrentLocation, GameObjects.WorldObjectBase.Objects.Tree))
            {
                this.SwitchFocusMakeVisible(UserInterfaceManager.Get <ChoppingWindow>());
            }
        }
Esempio n. 17
0
 // Use this for initialization
 void Start()
 {
     Instance          = this;
     gameStateManager  = GetComponent <GameStateManager>();
     worldObjects      = new List <GameObject>();
     worldObjectGroups = new List <GameObject>();
     InitializePrefabDictionary();
     InitializeStartingWorldObjects();
 }
Esempio n. 18
0
        public List <KeyValuePair <Type, int> > GetAllItemsInput(WorldObject objectAsk)
        {
            List <KeyValuePair <Type, int> > result = new List <KeyValuePair <Type, int> >();
            // User is the owner of the object that ask for the items
            User             user             = objectAsk.OwnerUser;
            List <Inventory> checkedInventory = new List <Inventory>();

            foreach (ConnectorObject conv in inputConveyors)
            {
                // If the connected input don't exist, destroy the connector
                if (WorldObjectManager.GetFromID(conv.Input.ObjectID) == null)
                {
                    conv.CleanDestroy();
                    break;
                }
                if (conv.Operating == false)
                {
                    continue;
                }
                // If the owner of the input object is authorized to interract with the conv
                if (Utils.IsAuthorizedToInteract(conv, user))
                {
                    // If the owner of the connector can interract with the output
                    if (Utils.IsAuthorizedToInteract(conv.Input, conv.OwnerUser))
                    {
                        if (conv.InvInput != null && checkedInventory.Contains(conv.InvInput) == false)
                        {
                            checkedInventory.Add(conv.InvInput);
                            foreach (var item in conv.InvInput.Stacks)
                            {
                                if (item.Quantity > 0)
                                {
                                    int qty = item.Quantity;
                                    int i   = 0;
                                    foreach (var kvp in result)
                                    {
                                        if (kvp.Key == item.Item.Type)
                                        {
                                            qty += kvp.Value;
                                            break;
                                        }
                                        i++;
                                    }
                                    if (qty != item.Quantity)
                                    {
                                        result.RemoveAt(i);
                                    }
                                    result.Add(new KeyValuePair <Type, int>(item.Item.Type, qty));
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 19
0
        public WorldObjectBase(string name, List <IItem> items, Objects objectType, ObjectActions objectActionType)
        {
            ObjectId = WorldObjectManager.GetUniqueWorldObjectId();
            WorldObjectManager.AddWorldObject(this);

            Name             = name;
            Items            = items;
            ObjectType       = objectType;
            ObjectActionType = objectActionType;
        }
Esempio n. 20
0
 // Use this for initialization
 void Start()
 {
     Instance           = this;
     timer              = 0;
     currentTurn        = 0;
     timeMultiplier     = 1;
     isPaused           = true;
     robotManager       = GetComponent <RobotManager>();
     worldObjectManager = GetComponent <WorldObjectManager>();
 }
Esempio n. 21
0
    void RotateObject()
    {
        //if (Physics.Raycast(_ray, out hit, Mathf.Infinity))
        //{
        Debug.Log("rotating");
        hitGO = hit.transform.gameObject;
        WOM = hitGO.transform.parent.parent.GetComponent<WorldObjectManager>();

        Debug.Log("eye hit:" + hit.transform.gameObject);
        WOM.GotHit = true;
    }
Esempio n. 22
0
    void Start()
    {
        itemLibrary = GetComponent <ItemLibrary>();
        itemLibrary.Initialize();

        itemManager            = new ItemManager(this, dropItemPool, dropItemPoolSize);
        worldObjectManager     = new WorldObjectManager(this, worldObjectTemplateList, worldObjectPool, worldObjectPoolSize);
        characterObjectManager = new CharacterObjectManager(this, characterObjectTemplateList, characterObjectPool, characterObjectPoolSize);

        uiManager = new UIManager(this);
    }
Esempio n. 23
0
        public static void Destroy()
        {
            // Clear and dispose all objects
            if (Objects != null)
            {
                Objects.Clear(true);
                Objects = null;
            }

            // Maps
            Mapcache.Destroy();
        }
 public override void OnLearned(User user)
 {
     base.OnLearned(user);
     foreach (var obj in WorldObjectManager.GetOwnedBy(user))
     {
         var requirements = obj.GetComponent <RoomRequirementsComponent>();
         if (requirements != null)
         {
             requirements.MarkDirty();
         }
     }
 }
Esempio n. 25
0
        public static void Main(string[] args)
        {
            //Lets do the loading here to catch any exceptions.
            Console.WriteLine("For future updates visit http://www.CamSpark.com");
            MapData.load();  //this has to be packed once all mapdata is gotten.
            ObjectData.load();
            ItemData.load(); //this has to be first because npcDrops use itemData.. i think.
            NpcData.load();  //first load the npc data.
            NpcDrop.load();  //second load the npc drops. [order does matter here, as it binds to npcData].
            NpcSpawn.load(); //finally you can spawn the npcs.
            LaddersAndStairs.load();
            objectManager     = new WorldObjectManager();
            groundItemManager = new GroundItemManager();
            shopManager       = new ShopManager();
            minigames         = new MinigamesHandler();
            grandExchange     = new GrandExchange();
            clanManager       = new ClanManager();
            packetHandlers    = new PacketHandlers();
            loginHandler      = new LoginHandler();

            registerEvent(new RunEnergyEvent());
            registerEvent(new LevelChangeEvent());
            registerEvent(new SpecialRestoreEvent());
            registerEvent(new SkullCycleEvent());
            registerEvent(new AreaVariables());
            registerEvent(new AggressiveNpcEvent());
            registerEvent(new LowerPotionCyclesEvent());
            objectManager.getFarmingPatches().processPatches();
            isRunning = true;
            new Thread(new ThreadStart(Server.gameThread)).Start();
            new Thread(new ThreadStart(Server.eventProcessingThread)).Start();

            Console.Title = "Runescape 2 530 C# Server";

            // Startup the Server Listener
            try
            {
                IPEndPoint ipe = new IPEndPoint(0, Constants.SERVER_PORT);
                serverListenerSocket = new System.Net.Sockets.Socket(ipe.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                serverListenerSocket.Bind(ipe);
                serverListenerSocket.Listen(25); //backlog
                serverListenerSocket.BeginAccept(new AsyncCallback(acceptCallback), serverListenerSocket);
                Console.WriteLine("Runescape 2 530 C# server started on port " + Constants.SERVER_PORT);
            }
            catch (SocketException ioe)
            {
                misc.WriteError("Error: Unable to startup listener on " + Constants.SERVER_PORT + " - port already in use?");
                misc.WriteError(ioe.Message.ToString());
                isRunning = false;
            }
        }
Esempio n. 26
0
        public override void OnAreaValid(GameActionPack pack, Player player, Vector3i position, Quaternion rotation)
        {
            var deed = PropertyManager.FindConnectedDeedOrCreate(player.User, position.XZ);

            foreach (var plotPosition in PlotUtil.GetAllPropertyPos(position, virtualOccupancy))
            {
                if (!this.IsPlotAuthorized(plotPosition, player.User, out var canClaimPlot))
                {
                    return;
                }

                if (canClaimPlot)
                {
                    pack.ClaimProperty(deed, player.User, player.User.Inventory, plotPosition, requirePapers: false);
                }
            }

            if (!pack.EarlyResult)
            {
                return;
            }

            pack.AddPostEffect(() =>
            {
                var camp      = WorldObjectManager.ForceAdd(typeof(CampsiteObject), player.User, position, rotation, false);
                var stockpile = WorldObjectManager.ForceAdd(typeof(TinyStockpileObject), player.User, position + rotation.RotateVector(Vector3i.Right * 3), rotation, false);
                player.User.OnWorldObjectPlaced.Invoke(camp);
                player.User.Markers.Add(camp.Position3i + Vector3i.Up, camp.UILinkContent(), false);
                var storage   = camp.GetComponent <PublicStorageComponent>();
                var changeSet = new InventoryChangeSet(storage.Inventory);
                PlayerDefaults.GetDefaultCampsiteInventory().ForEach(x => changeSet.AddItems(x.Key, x.Value, storage.Inventory));

                //If we're running a settlement system, create the homestead item now and fill it with homestead-specific claim papers.
                if (SettlementPluginConfig.Obj.SettlementSystemEnabled)
                {
                    var marker     = WorldObjectManager.ForceAdd(typeof(HomesteadMarkerObject), player.User, position + rotation.RotateVector(new Vector3i(3, 0, 3)), rotation, false);
                    var markerComp = marker.GetComponent <SettlementMarkerComponent>();
                    markerComp.Settlement.Citizenship.AddSpawnedClaims(this.bonusPapers);
                    markerComp.UpdateSpawnedClaims();
                }
                else
                {
                    //For the old system, add the papers to the tent.
                    if (this.bonusPapers > 0)
                    {
                        changeSet.AddItems(typeof(PropertyClaimItem), this.bonusPapers);
                    }
                }
                changeSet.Apply();
            });
        }
Esempio n. 27
0
 private void update()
 {
     if (inputConveyors.Count > 0 && outputConveyors.Count > 0)
     {
         UpdateElectricityCost();
         foreach (ConnectorObject convIn in inputConveyors)
         {
             if (WorldObjectManager.GetFromID(convIn.Input.ObjectID) == null)
             {
                 convIn.CleanDestroy();
                 break;
             }
             if (convIn.Operating == false)
             {
                 continue;
             }
             PropertyAuthComponent convInAuth = convIn.Input.GetComponent <PropertyAuthComponent>();
             // If the owner of the connector input can interract with the stockpile
             if ((convIn.OwnerUser == null && convIn.Input.OwnerUser == null) || (convIn.OwnerUser != null && convIn.Input.AuthorizedToInteract(convIn.OwnerUser).Success))
             {
                 foreach (ConnectorObject convOut in outputConveyors)
                 {
                     if (WorldObjectManager.GetFromID(convOut.Output.ObjectID) == null)
                     {
                         convOut.CleanDestroy();
                         break;
                     }
                     if (convOut.Operating == false)
                     {
                         continue;
                     }
                     PropertyAuthComponent convOutAuth = convOut.Output.GetComponent <PropertyAuthComponent>();
                     // If the owner of the input can interract with the owner of the output
                     if ((convIn.OwnerUser == null && convOut.OwnerUser == null) || (convIn.OwnerUser != null && convOut.AuthorizedToInteract(convIn.OwnerUser).Success))
                     {
                         // If the owner of the connector output can interract with the stockpile
                         if ((convOut.OwnerUser == null && convOut.Output.OwnerUser == null) || (convOut.OwnerUser != null && convOut.Output.AuthorizedToInteract(convOut.OwnerUser).Success))
                         {
                             if (Utils.MoveItemFromToInventory(convIn.InvInput, convOut.InvOutput, 1, convIn.filter, convOut.filter))
                             {
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 28
0
        private static void ChopWood()
        {
            var player          = Game.GameSession.Player;
            var currentLocation = LocationManager.GetLocationByObjectId <ILocation>(player.CurrentLocation.ObjectId);

            if (WorldObjectManager.ContainsWorldObject(currentLocation, WorldObjectBase.Objects.Tree))
            {
                var tree = WorldObjectManager.GetLocationWorldObjectsByObjectType <IWorldObject>(currentLocation, WorldObjectBase.Objects.Tree).FirstOrDefault();

                var reward = tree.Items.FirstOrDefault();

                InventoryManager.AddToInventory <PlayerInventory>(reward);
                MessageManager.AddItemObtained(reward.Name, 1);
            }
        }
Esempio n. 29
0
        private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
        {
            DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
            if (QSBCore.IsInMultiplayer)
            {
                WorldObjectManager.Rebuild(newScene);
            }
            var universe = InUniverse(newScene);

            OnSceneLoaded?.SafeInvoke(newScene, universe);
            if (universe)
            {
                OnUniverseSceneLoaded?.SafeInvoke(newScene);
            }
        }
Esempio n. 30
0
        public override InteractResult OnActLeft(InteractionContext context)
        {
            // if I target a pipe with the wrench, I transform it to a connector set to input
            if (context.HasBlock && context.Block is BaseTransportPipeBlock && Utils.SearchForConnectedInventory(context.BlockPosition.Value) != null)
            {
                //Removing the block and add the connector
                World.DeleteBlock(context.BlockPosition.Value);
                ConnectorObject connector = WorldObjectManager.TryToAdd <ConnectorObject>(context.Player.User, context.BlockPosition.Value, Quaternion.Identity);
                // If the conenctor can't be added just reset the action
                if (connector == null)
                {
                    World.SetBlock(context.Block.GetType(), context.BlockPosition.Value);
                    return(InteractResult.NoOp);
                }
                // I instanciate the connector info with the info from the pipe
                TransportPipeInfo info = null;
                if (TransportPipeManager.pipesInfo.TryGetValue(context.BlockPosition.Value, out info))
                {
                    connector.info = info;
                    context.Player.SendTemporaryMessage($"Set to input");
                    connector.mode = CONNECTOR_MODE.Input;

                    BurnCalories(context.Player);
                    UseDurability(1.0f, context.Player);

                    return(InteractResult.Success);
                }
                else
                {
                    // If the pipe don't contains any info I recreate the linker from the pipe and reset the action
                    connector.Destroy();
                    World.SetBlock(context.Block.GetType(), context.BlockPosition.Value);
                    Utils.RecreateLinker(context.BlockPosition.Value, new TransportPipeLinker());
                }
            }
            // If I use the wrench on a connector
            if (context.HasTarget && context.Target is ConnectorObject)
            {
                // I process the config inside the connector class
                (context.Target as ConnectorObject).ProcessConfig(context);
                BurnCalories(context.Player);
                UseDurability(1.0f, context.Player);
                return(InteractResult.Success);
            }
            return(InteractResult.NoOp);
        }
Esempio n. 31
0
    public override InteractResult OnActLeft(InteractionContext context)
    {
        if (context.HasBlock && !context.Block.Is <Impenetrable>())
        {
            World.DeleteBlock(context.BlockPosition.Value);
            var plant = EcoSim.PlantSim.GetPlant(context.BlockPosition.Value + Vector3i.Up);
            if (plant != null)
            {
                EcoSim.PlantSim.DestroyPlant(plant, DeathType.DivineIntervention);
            }

            RoomData.QueueRoomTest(context.BlockPosition.Value);
            return(InteractResult.Success);
        }
        else if (context.HasTarget)
        {
            if (context.Target != null)
            {
                if (context.Target is WorldObject obj)
                {
                    WorldObjectManager.DestroyPermanently(obj);
                }
                if (context.Target is PickupableBlock)
                {
                    World.DeleteBlock(context.BlockPosition.Value);
                }
                else if (context.Target is RubbleObject)
                {
                    (context.Target as RubbleObject).Destroy();
                }
                else if (context.Target is TreeEntity)
                {
                    (context.Target as TreeEntity).Destroy();
                }
                else if (context.Target is Animal)
                {
                    (context.Target as Animal).Destroy();
                }
            }
            return(InteractResult.Success);
        }
        else
        {
            return(InteractResult.NoOp);
        }
    }
Esempio n. 32
0
        private void AdvanceToNextLevel(GameTime gameTime)
        {
            _gameData.levelReached[CurrentChapterNumber] = CurrentLevelNumber;
            ++CurrentLevelNumber;

            switch (CurrentLevelNumber)
            {
                case 1:
                    //play start cutscene. then start the level.
                    if (CurrentChapterNumber == 0 && _gameData.levelReached[CurrentChapterNumber] == 0)
                    {
                        activeCutscene = new Cutscene("Cutscenes/intro2");
                        gameRunState = GameState.StateCutscene;
                    }
                    goto default;
                case 11:
                    CurrentLevelNumber = 1;
                    ++CurrentChapterNumber;
                    goto default;
                default:
                    try
                    {
                        objectManager = new WorldObjectManager(graphics, Content, string.Concat(ContentDirectory, ChapterPaths[CurrentChapterNumber], CurrentLevelNumber.ToString(), ".xml"), CurrentLevelNumber);

                        objectManager.StartTime = gameTime.TotalGameTime;
                    }
                    catch (System.Xml.XmlException e)
                    {
                        // Next level doesnt exist. Go to next chapter.
                        goto case 11;

                    }
                    catch (System.IndexOutOfRangeException e)
                    {
                        // Next chapter doesnt exist. You've beaten the game.

                    }
                    break;
            }
            SaveData();

            stopGame();
        }
Esempio n. 33
0
        private void processPauseMenuTouch(GameTime gameTime, GestureSample gesture)
        {
            pauseMenu.ProcessTouch(gesture);

            switch (pauseMenu.flag)
            {
                case GameMenuFlag.LoadNextLevel:
                    AdvanceToNextLevel(gameTime);
                    break;

                case GameMenuFlag.ToTitleScreen:
                    MusicManager.StopMusic();
                    titleScreen = new TitleScreen(graphics, _gameData);
                    gameRunState = GameState.StateMenu;
                    break;
                case GameMenuFlag.Replay:
                    /*if (cityActiveInstance.State == SoundState.Playing)
                        cityActiveInstance.Pause();
                    if (menuMusicInstance.State == SoundState.Playing)
                        menuMusicInstance.Pause();*/
                    objectManager.WOMstate = WOMState.InLevel;
                    stopGame();
                    break;
                case GameMenuFlag.LoadSpecificLevel:
                    int levelnumber = LevelParser.getCurrentLevelNumber();
                    string path = LevelParser.getReadTarget();
                    objectManager = new WorldObjectManager(graphics, Content, string.Concat(path.Substring(0, path.LastIndexOf("/") + 1), levelnumber.ToString() + ".xml"), levelnumber);
                    stopGame();
                    break;

            }
        }