/// <summary> /// 移除建筑 /// </summary> /// <param name="player">玩家</param> /// <param name="factory">工厂</param> /// <param name="objId">实体id/预建筑id</param> /// <returns></returns> public static bool RemoveBuild(Player player, PlanetFactory factory, int objId) { try { if (player.package.isFull) { UIRealtimeTip.Popup(ST.背包不足); return(false); } int num = -objId; ItemProto itemProto = null; if (objId > 0) { itemProto = LDB.items.Select((int)factory.entityPool[objId].protoId); } if (num > 0) { itemProto = LDB.items.Select((int)factory.prebuildPool[num].protoId); } int itemId = (itemProto == null) ? 0 : itemProto.ID; factory.DestructFinally(player, objId, ref itemId); player.package.AddItemStacked(itemId, 1); UIItemup.Up(itemId, 1); return(true); } catch (Exception e) { Debug.LogError(e.Message); Debug.LogError(e.StackTrace); return(false); } }
public void ProcessPacket(DestructEntityRequest packet, NebulaConnection conn) { PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId); // We only execute the code if the client has loaded the factory at least once. // Else it will get it once it goes to the planet for the first time. if (planet.factory != null) { int protoId = 0; using (FactoryManager.EventFromServer.On()) using (FactoryManager.DoNotAddItemsFromBuildingOnDestruct.On(packet.AuthorId != LocalPlayer.PlayerId)) { if (packet.AuthorId == LocalPlayer.PlayerId) { //I am author so I will take item as a building PlayerAction_Build pab = GameMain.mainPlayer.controller?.actionBuild; if (pab != null) { int itemId = (packet.ObjId > 0 ? LDB.items.Select((int)planet.factory.entityPool[packet.ObjId].protoId) : LDB.items.Select((int)planet.factory.prebuildPool[-packet.ObjId].protoId))?.ID ?? -1; //Todo: Check for the full accumulator building if (itemId != -1) { GameMain.mainPlayer.TryAddItemToPackage(itemId, 1, true, packet.ObjId); UIItemup.Up(itemId, 1); } } } planet.factory.DestructFinally(GameMain.mainPlayer, packet.ObjId, ref protoId); } } }
public override void ProcessPacket(ReturnItemsPacket packet, INebulaConnection conn) { List <ItemPackageL> items = packet.GetData(); foreach (ItemPackageL item in items) { int upCount = GameMain.mainPlayer.TryAddItemToPackage(item.item, item.stack, item.stack, true); UIItemup.Up(item.item, upCount); } }
public void ProcessPacket(DestructEntityRequest packet, NebulaConnection conn) { PlanetData planet = GameMain.galaxy.PlanetById(packet.PlanetId); // We only execute the code if the client has loaded the factory at least once. // Else it will get it once it goes to the planet for the first time. if (planet.factory != null) { int protoId = 0; using (FactoryManager.EventFromServer.On()) using (FactoryManager.DoNotAddItemsFromBuildingOnDestruct.On(packet.AuthorId != LocalPlayer.PlayerId)) { if (packet.AuthorId == LocalPlayer.PlayerId) { //I am author so I will take item as a building PlayerAction_Build pab = GameMain.mainPlayer.controller?.actionBuild; if (pab != null) { int itemId = (packet.ObjId > 0 ? LDB.items.Select((int)planet.factory.entityPool[packet.ObjId].protoId) : LDB.items.Select((int)planet.factory.prebuildPool[-packet.ObjId].protoId))?.ID ?? -1; //Todo: Check for the full accumulator building if (itemId != -1) { GameMain.mainPlayer.TryAddItemToPackage(itemId, 1, true, packet.ObjId); UIItemup.Up(itemId, 1); } } } if (packet.PlanetId != GameMain.mainPlayer.planetId) { //Creating rendering batches is required to properly handle DestructFinally for the belts, since model needs to be changed. //ToDo: Optimize it somehow, since creating and destroying rendering batches is not optimal. planet.factory.cargoTraffic.CreateRenderingBatches(); } planet.factory.DestructFinally(GameMain.mainPlayer, packet.ObjId, ref protoId); if (packet.PlanetId != GameMain.mainPlayer.planetId) { planet.factory.cargoTraffic.DestroyRenderingBatches(); } } } }
// This function is based on PlayerAction_Mine.GameTick public void DroneGameTick() { double powerFactor = 0.01666666753590107; PlanetFactory factory = this.player.factory; if (factory == null) { // This has only been seen briefly when the Render Distance mod is transitioning to or from a planet view. return; } double miningEnergyCost = this.player.mecha.miningPower * powerFactor; double energyAvailable; float fractionOfEnergyAvailable; this.player.mecha.QueryEnergy(miningEnergyCost, out energyAvailable, out fractionOfEnergyAvailable); int miningTime = (int)(this.player.mecha.miningSpeed * configSpeedScaleFactor * fractionOfEnergyAvailable * 10000f + 0.49f); VegeData vegeData = factory.GetVegeData(this.miningId); this.miningProtoId = (int)vegeData.protoId; VegeProto vegeProto = LDB.veges.Select((int)vegeData.protoId); if (vegeProto != null) { this.miningTick += miningTime; this.player.mecha.coreEnergy -= energyAvailable; this.player.mecha.MarkEnergyChange(5, -miningEnergyCost); this.percent = Mathf.Clamp01((float)((double)this.miningTick / (double)(vegeProto.MiningTime * 10000))); if (this.miningTick >= vegeProto.MiningTime * 10000) { System.Random random = new System.Random(vegeData.id + ((this.player.planetData.seed & 16383) << 14)); bool inventoryOverflowFlag = false; int popupQueueIndex = 0; for (int itemIdx = 0; itemIdx < vegeProto.MiningItem.Length; itemIdx++) { float randomMiningChance = (float)random.NextDouble(); if (randomMiningChance < vegeProto.MiningChance[itemIdx]) { int minedItem = vegeProto.MiningItem[itemIdx]; int minedItemCount = (int)((float)vegeProto.MiningCount[itemIdx] * (vegeData.scl.y * vegeData.scl.y) + 0.5f); if (minedItemCount > 0 && LDB.items.Select(minedItem) != null) { int inventoryOverflowCount = this.player.package.AddItemStacked(minedItem, minedItemCount); if (inventoryOverflowCount != 0) { UIItemup.Up(minedItem, inventoryOverflowCount); UIRealtimeTip.PopupItemGet(minedItem, inventoryOverflowCount, vegeData.pos + vegeData.pos.normalized, popupQueueIndex++); } else // Unable to fit all items { inventoryOverflowFlag = true; } } } } VFEffectEmitter.Emit(vegeProto.MiningEffect, vegeData.pos, vegeData.rot); VFAudio.Create(vegeProto.MiningAudio, null, vegeData.pos, true); factory.RemoveVegeWithComponents(vegeData.id); GameMain.gameScenario.NotifyOnVegetableMined((int)vegeData.protoId); this.miningType = EObjectType.Entity; // This change will cause the mission to be completed. this.miningId = 0; if (inventoryOverflowFlag) { //Logger.LogInfo("Inventory overflow detected."); } this.miningTick = 0; } } else { //Logger.LogInfo("null vegeProto. Icarus likely removed clearing target."); this.miningType = EObjectType.Entity; // This change will cause the mission to be completed. this.miningId = 0; this.miningTick = 0; this.percent = 0f; factory.RemoveVegeWithComponents(vegeData.id); } }
// 添加物品 void AddItemTable(Rect AddItemTableRect) { if (GameMain.mainPlayer == null) { GUILayout.Label("请先进入游戏", new GUIStyle { fontSize = 26, fixedWidth = 700, fixedHeight = 300, alignment = TextAnchor.MiddleCenter }); return; } Texture2D texture2D = new Texture2D(1, 1, TextureFormat.RGBA32, false); texture2D.SetPixel(0, 0, new Color32(30, 144, 255, 255)); // rgba(30, 144, 255,1.0) texture2D.Apply(); Texture2D texture2D2 = new Texture2D(1, 1, TextureFormat.RGBA32, false); texture2D2.SetPixel(0, 0, new Color32(112, 161, 255, 255)); // rgba(112, 161, 255,1.0) texture2D2.Apply(); // 按钮样式 GUIStyle guistyle = new GUIStyle { normal = new GUIStyleState // 正常样式 { textColor = Color.white, background = texture2D }, active = new GUIStyleState // 点击样式 { textColor = Color.white, background = texture2D2 }, wordWrap = true, alignment = TextAnchor.MiddleCenter, fixedHeight = 40, fixedWidth = 90, margin = new RectOffset(5, 7, 0, 5), }; // 物品列表 ItemProto[] dataArray = LDB.items.dataArray; GUILayout.BeginArea(AddItemTableRect); { scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.Width(700), GUILayout.Height(300)); { GUILayout.BeginHorizontal(new GUIStyle { alignment = TextAnchor.UpperLeft }); for (int i = 0; i < dataArray.Length; i++) { var item = dataArray[i]; if (searchItem == "") { // 普通模式 if (GUILayout.Button(item.name, guistyle)) { int num = AddItemNum; int res = GameMain.mainPlayer.package.AddItemStacked(item.ID, num); UIItemup.Up(item.ID, num); //// 添加物品代码 //int ID = 6001; //int num = 1000; //int res = GameMain.mainPlayer.package.AddItemStacked(ID, num); //UIItemup.Up(ID, num); } } else { // 如果用户输入搜索 if (item.name.Contains(searchItem)) { if (GUILayout.Button(item.name, guistyle)) { int num = AddItemNum; int res = GameMain.mainPlayer.package.AddItemStacked(item.ID, num); UIItemup.Up(item.ID, num); } } } int listNum = 7; if ((i + 1) % listNum == 0) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUIStyle { alignment = TextAnchor.UpperLeft }); } } if (searchItem == "" || "沙土".Contains(searchItem)) { if (GUILayout.Button("沙土", guistyle)) { GameMain.mainPlayer.SetSandCount(GameMain.mainPlayer.sandCount + AddItemNum); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } GUILayout.EndArea(); }
public static bool OnWarperIconClickPrefix(UIStationWindow __instance, ref int obj) { if ((__instance.stationId == 0 || __instance.factory == null)) { __instance._Close(); return(false); } StationComponent stationComponent = __instance.transport.stationPool[__instance.stationId]; ItemProto gigaProto = LDB.items.Select(__instance.factory.entityPool[stationComponent.entityId].protoId); if (gigaProto.ID != GigaStationsPlugin.pls.ID && gigaProto.ID != GigaStationsPlugin.ils.ID && gigaProto.ID != GigaStationsPlugin.collector.ID) { return(true); // not my ILS, return to original code } if (__instance.stationId == 0 || __instance.factory == null) { return(false); } if (stationComponent.id != __instance.stationId) { return(false); } if (!stationComponent.isStellar) { return(false); } if (__instance.player.inhandItemId > 0 && __instance.player.inhandItemCount == 0) { __instance.player.SetHandItems(0, 0); } else if (__instance.player.inhandItemId > 0 && __instance.player.inhandItemCount > 0) { int num = 1210; ItemProto itemProto = LDB.items.Select(num); if (__instance.player.inhandItemId != num) { UIRealtimeTip.Popup("只能放入".Translate() + itemProto.name); return(false); } int num2 = GigaStationsPlugin.ilsMaxWarps; int warperCount = stationComponent.warperCount; int num3 = num2 - warperCount; if (num3 < 0) { num3 = 0; } int num4 = (__instance.player.inhandItemCount >= num3) ? num3 : __instance.player.inhandItemCount; if (num4 <= 0) { UIRealtimeTip.Popup("栏位已满".Translate()); return(false); } stationComponent.warperCount += num4; __instance.player.AddHandItemCount_Unsafe(-num4); if (__instance.player.inhandItemCount <= 0) { __instance.player.SetHandItemId_Unsafe(0); __instance.player.SetHandItemCount_Unsafe(0); } } else if (__instance.player.inhandItemId == 0 && __instance.player.inhandItemCount == 0) { int warperCount2 = stationComponent.warperCount; int num5 = warperCount2; if (num5 <= 0) { return(false); } if (VFInput.shift || VFInput.control) { num5 = __instance.player.package.AddItemStacked(1210, num5, 0, out int _); if (warperCount2 != num5) { UIRealtimeTip.Popup("无法添加物品".Translate()); } UIItemup.Up(1210, num5); } else { __instance.player.SetHandItemId_Unsafe(1210); __instance.player.SetHandItemCount_Unsafe(num5); } stationComponent.warperCount -= num5; if (stationComponent.warperCount < 0) { Assert.CannotBeReached(); stationComponent.warperCount = 0; } } return(false); }
// 添加物品 void AddItemTable(Rect AddItemTableRect) { if (GameMain.mainPlayer == null) { GUILayout.Label("请先进入游戏", new GUIStyle { fontSize = 26, fixedWidth = 700, fixedHeight = 300, alignment = TextAnchor.MiddleCenter }); return; } Rect HeaderTableRect = new Rect(0, 40, 700, 40); AddItemHeader(HeaderTableRect); // 物品列表 ItemProto[] dataArray = LDB.items.dataArray; AddItemTableRect.y += 30; GUILayout.BeginArea(AddItemTableRect); { scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUILayout.Width(700), GUILayout.Height(300)); { GUILayout.BeginHorizontal(new GUIStyle { alignment = TextAnchor.UpperLeft }); for (int i = 0; i < dataArray.Length; i++) { var item = dataArray[i]; if (searchItem == "") { // 普通模式 //if (XmGUI.Button(item.name)) if (XmGUI.Button(item.name, item.iconSprite.texture)) { int num = AddItemNum; int res = GameMain.mainPlayer.package.AddItemStacked(item.ID, num); UIItemup.Up(item.ID, num); //// 添加物品代码 //int ID = 6001; //int num = 1000; //int res = GameMain.mainPlayer.package.AddItemStacked(ID, num); //UIItemup.Up(ID, num); } } else { // 如果用户输入搜索 if (item.name.Contains(searchItem)) { if (XmGUI.Button(item.name, item.iconSprite.texture)) { int num = AddItemNum; int res = GameMain.mainPlayer.package.AddItemStacked(item.ID, num); UIItemup.Up(item.ID, num); } } } int listNum = 5; // 每行个数 if ((i + 1) % listNum == 0) { XmGUI.hr(); } } if (searchItem == "" || "沙土".Contains(searchItem)) { if (XmGUI.Button("沙土")) { GameMain.mainPlayer.SetSandCount(GameMain.mainPlayer.sandCount + AddItemNum); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } GUILayout.EndArea(); }