static void Prefix(NPCBase npc, ref bool gotFood) { DebugLog.Write(MethodBase.GetCurrentMethod().DeclaringType + "::" + MethodBase.GetCurrentMethod().Name, npc); inFunctionStockpile = npc.Colony.Stockpile; ColonyShopVisitTrackerHookOnVisit.npc = npc; }
static void Prefix(SortedList <ushort, int> __instance, int index, int val) { Stockpile stockpile = ColonyShopVisitTrackerHookOnVisit.inFunctionStockpile; if (stockpile == null) { DebugLog.Write(MethodBase.GetCurrentMethod().DeclaringType + "::" + MethodBase.GetCurrentMethod().Name, "INVALID SOTKCPILE"); return; } if (stockpile.Owner == null) { DebugLog.Write(MethodBase.GetCurrentMethod().DeclaringType + "::" + MethodBase.GetCurrentMethod().Name, "INVALID OWNER"); return; } DebugLog.Write(MethodBase.GetCurrentMethod().DeclaringType + "::" + MethodBase.GetCurrentMethod().Name); int difference = __instance.GetValueAtIndex(index) - val; ushort type = __instance.GetKeyAtIndex(index); if (difference > 0) { InventoryStatistics.RemoveInventory(stockpile.Owner, type, difference); } else { InventoryStatistics.AddInventory(stockpile.Owner, type, -difference); } }
private void SplitStockpileOnLeave(Players.Player player) { Stockpile player_Stockpile = Stockpile.GetStockPile(player); Stockpile fake_player_Stockpile = Stockpile.GetStockPile(fake_player); int split = playersOnTeam.Count + 1; player_Stockpile._items.Clear(); for (ushort item = 0; item < ItemTypes.IndexLookup.MaxRegistered; item++) { int amount = fake_player_Stockpile.AmountContained(item); amount = amount / split; if (amount > 0) { player_Stockpile.Add(item, amount); fake_player_Stockpile.TryRemove(item, amount); } } player.SendStockpileInventory(); fake_player.SendStockpileInventory(); }
static void Postfix(NPCBase npc, ref bool gotFood) { // Log.WriteWarning("StockpileHookTryRemoveFood::Postfix"); inFunctionStockpile = null; isFood = false; ColonyShopVisitTrackerHookOnVisit.npc = null; }
public BaseWorld(WorldInfo worldInfo, RelationshipMap relationshipMap, Vector3 firePlace) { _worldInfo = worldInfo; EntityMapping = new EntityMapping(relationshipMap); Entities = new EntitiesController(EntityMapping); FreeCitizens = new Queue <Actor>(); Stockpile = new Stockpile(); Events = new WorldEventsController(); MaxPopulation = _worldInfo.MaxPopulation; RelationshipMap = relationshipMap; MinPopulation = _worldInfo.MinPopulation; FirePlace = firePlace; TaxController = new PerCitizenResourceController(new[] { -2, -1, 0, 1, 2 }, new[] { 2, 1, 0, -1, -2 }); // TODO: Flawed logic, food can be 1/8 at least. Might need to redesign food amounts and shieeet FoodController = new PerCitizenResourceController(new[] { 0, 1, 2, 3 }, new[] { -1, 0, 1, 2 }); TaxController.SetValueIndex(2); FoodController.SetValueIndex(1); _popularityInternal = _worldInfo.MaxPopularity; }
public void SetNPC(NPCBase npc) { NPC = npc; if (npc != null) { NeedsNPC = false; IsValid = true; Owner = npc.Colony; _tmpVals = npc.CustomData; _colony = npc.Colony; _inv = SettlerInventory.GetSettlerInventory(npc); _colonyState = ColonyState.GetColonyState(_colony); _stock = npc.Colony.Stockpile; } else { NeedsNPC = true; IsValid = false; Owner = null; _inv = null; _tmpVals = null; _colony = null; _colonyState = null; _stock = null; } }
private async void btnSaveStockpile_Click(object sender, EventArgs e) { Stockpile sks = new Stockpile(dgvStockpile); var ghForm = UI_CanvasForm.GetExtraForm("Glitch Harvester"); try { UICore.SetHotkeyTimer(false); //We do this here and invoke because our unlock runs at the end of the awaited method, but there's a chance an error occurs //Thus, we want this to happen within the try block SyncObjectSingleton.FormExecute(() => { UICore.LockInterface(false, true); S.GET <UI_SaveProgress_Form>().Dock = DockStyle.Fill; ghForm?.OpenSubForm(S.GET <UI_SaveProgress_Form>()); }); await Task.Run(() => { saveStockpile(sks, StockpileManager_UISide.CurrentStockpile.Filename); }); } finally { SyncObjectSingleton.FormExecute(() => { ghForm?.CloseSubForm(); UICore.UnlockInterface(); UICore.SetHotkeyTimer(true); }); } }
public static void DoGamble(Players.Player player) { if (player != null) { var priceItem = PickLoot(); ushort priceType; if (SPECIAL_SCIENCE.Equals(priceItem.Typename)) { Chat.Send(player, "Jackpot! Just found the solution to your current research"); ScienceManager.GetPlayerManager(player).AddActiveResearchProgress(1000000); } else if (SPECIAL_DEATH.Equals(priceItem.Typename)) { Chat.Send(player, "Fatal! Something inside killed you"); Players.TakeHit(player, 1000000); } else if (!ItemTypes.IndexLookup.TryGetIndex(priceItem.Typename, out priceType)) { Log.WriteError($"Unknown gambling price {priceItem.Typename} won by {player}"); Chat.Send(player, "I have bad feelings about this"); } else if (priceType == BuiltinBlocks.Air) { Chat.Send(player, "You found an empty box :-("); } else { Chat.Send(player, $"You found {priceItem.Amount} x {priceItem.Typename} as loot!"); if (!Inventory.GetInventory(player).TryAdd(priceType, priceItem.Amount)) { Stockpile.GetStockPile(player).Add(priceType, priceItem.Amount); } } } }
public override void OnNPCAtStockpile(ref NPCBase.NPCState state) { if (state.Inventory.IsEmpty) { Assert.IsTrue(shouldTakeItems); } else { state.Inventory.Dump(usedNPC.Colony.UsedStockpile); } state.SetCooldown(0.5); state.JobIsDone = true; if (shouldTakeItems) { shouldTakeItems = false; ScienceManagerPlayer scienceManager; if (!ScienceManager.TryGetPlayerManager(owner, out scienceManager)) { return; } ResearchProgress active = scienceManager.ActiveResearch; if (active.research != null && !active.IsCompleted) { var requirements = active.research.GetScienceRequirements(); if (Stockpile.GetStockPile(owner).TryRemove(requirements)) { state.Inventory.Add(requirements); } } } }
static void Prefix(SortedList <ushort, int> __instance, int index, int val) { Stockpile stockpile = ColonyShopVisitTrackerHookOnVisit.inFunctionStockpile; if (stockpile == null) { // Log.Write("SortedListHookSetValueAtIndex INVALID STOCKPILE"); return; } if (stockpile.Owner == null) { // Log.Write("SortedListHookSetValueAtIndex INVALID OWNER"); return; } // Log.WriteWarning("SortedListHookSetValueAtIndex"); int difference = __instance.GetValueAtIndex(index) - val; ushort type = __instance.GetKeyAtIndex(index); if (difference > 0) { InventoryStatistics.RemoveInventory(stockpile.Owner, type, difference); } else { InventoryStatistics.AddInventory(stockpile.Owner, type, -difference); } }
/// <summary> /// INTERNAL /// From gives to items. /// </summary> /// <param name="from">The player sending the items.</param> /// <param name="to">The player recieving the items.</param> /// <param name="give">The ItemID of the item given.</param> /// <param name="giveamt">How many of the item given.</param> public static void tradeGive(Players.Player from, Players.Player to, ushort give, int giveamt) { if (getTradeEnabled()) { Stockpile playerStockpile = Stockpile.GetStockPile(from); Stockpile partnerStockpile = Stockpile.GetStockPile(to); string name; bool legalIds = ItemTypes.IndexLookup.TryGetName(give, out name); if (!legalIds) { Helpers.Chat.sendSilent(from, "Invalid ID's", Helpers.Chat.ChatColour.orange); return; } if (playerStockpile.AmountContained(give) <= giveamt) { Helpers.Chat.sendSilent(from, "You can't afford that.", Helpers.Chat.ChatColour.orange); return; } playerStockpile.Remove(give, giveamt); partnerStockpile.Add(give, giveamt); Helpers.Chat.sendSilent(from, "You sent " + giveamt + " " + name + " to " + to.Name + ".", Helpers.Chat.ChatColour.orange); Helpers.Chat.sendSilent(to, from.Name + " sent " + giveamt + " " + name + " to you.", Helpers.Chat.ChatColour.orange); } else { Helpers.Chat.sendSilent(from, "Trade Disabled.", Helpers.Chat.ChatColour.red); } }
/// <summary> /// INTERNAL /// Trashes items. /// </summary> /// <param name="item">The ItemID of the item given.</param> /// <param name="amount">How many of the item given.</param> public static void trashItems(Players.Player player, ushort item, int amount) { if (Permissions.PermissionsManager.CheckAndWarnPermission(player, "trash")) { Stockpile playerStockpile = Stockpile.GetStockPile(player); string name; bool legalIds = ItemTypes.IndexLookup.TryGetName(item, out name); if (!legalIds) { Helpers.Chat.sendSilent(player, "Invalid ID's", Helpers.Chat.ChatColour.orange); return; } int stockPileAmount = playerStockpile.AmountContained(item); if (stockPileAmount <= amount) { Helpers.Chat.sendSilent(player, "You have less than " + amount + ", trashing all.", Helpers.Chat.ChatColour.orange); amount = stockPileAmount; } playerStockpile.Remove(item, amount); Helpers.Chat.sendSilent(player, String.Format("{0} of item [{1}] trashed.", amount, name), Helpers.Chat.ChatColour.orange); } else { Helpers.Chat.sendSilent(player, "Trashing Failed.", Helpers.Chat.ChatColour.red); } }
public static void CloseAllRtcForms() //This allows every form to get closed to prevent RTC from hanging { if (isClosing) { return; } isClosing = true; foreach (Form frm in UICore.AllColorizedSingletons()) { if (frm != null) { frm.Close(); } } if (S.GET <RTC_Standalone_Form>() != null) { S.GET <RTC_Standalone_Form>().Close(); } //Clean out the working folders if (!CorruptCore.RtcCore.DontCleanSavestatesOnQuit) { Stockpile.EmptyFolder("WORKING"); } Environment.Exit(0); }
// Run on add to world (also runs when added by game - ie: when a crop grows to the next stage) public void OnAddAction(Vector3Int position, ushort newType, Players.Player causedBy) { ushort num; // check if the block below is fertile if (World.TryGetTypeAt(position.Add(0, -1, 0), out num) && ItemTypes.IsFertile(num)) { CropManager.trackCrop(position, this); } else { // Tell the user you can't do this Pipliz.Chatting.Chat.Send(causedBy, string.Format("{0} can't grow here! It's not fertile!", ItemTypes.IndexLookup.GetName(newType))); // Get the air block, and replace the new crop with it ushort airBlockID = ItemTypes.IndexLookup.GetIndex("air"); ServerManager.TryChangeBlock(position, airBlockID); // Give the user the block Stockpile s = Stockpile.GetStockPile(causedBy); // Give them an item back? s.Add(newType, 1); // Update it? s.SendUpdate(); } }
public static ushort Refuel(Players.Player player, MachineState machineState) { var ps = PlayerState.GetPlayerState(player); if (machineState.Fuel < .75f) { if (!MachineState.MAX_FUEL.ContainsKey(player)) { MachineState.MAX_FUEL[player] = MachineState.DEFAULT_MAX_FUEL; } var stockpile = Stockpile.GetStockPile(player); foreach (var item in FuelValues) { while ((stockpile.AmountContained(item.Key) > 100 || item.Key == BuiltinBlocks.Firewood || item.Key == BuiltinBlocks.Coalore) && machineState.Fuel < MachineState.MAX_FUEL[player]) { stockpile.TryRemove(item.Key); machineState.Fuel += item.Value; } } if (machineState.Fuel < MachineState.MAX_FUEL[player]) { return(FuelValues.First().Key); } } return(GameLoader.Refuel_Icon); }
private bool runningTimer = false; //bool to run timer void Start() { objObjectList = GameObject.Find("ObjectLists"); objectList = objObjectList.GetComponent <ListOfObjects>(); StockpileScript = StockpileObj.GetComponent <Stockpile>(); thisUnit = gameObject.GetComponent <UnitV2>(); }
/// <summary> /// INTERNAL /// From gives to items. /// </summary> /// <param name="from">The player sending the items.</param> /// <param name="to">The player recieving the items.</param> /// <param name="give">The ItemID of the item given.</param> /// <param name="giveamt">How many of the item given.</param> public static void tradeGive(Players.Player from, Players.Player to, ushort give, int giveamt) { Stockpile playerStockpile = Stockpile.GetStockPile(from); Stockpile partnerStockpile = Stockpile.GetStockPile(to); string name; bool legalIds = ItemTypes.IndexLookup.TryGetName(give, out name); if (!legalIds) { Chat.Send(from, "Invalid ID's"); return; } if (playerStockpile.AmountContained(give) <= giveamt) { Chat.Send(from, "You can't afford that."); return; } playerStockpile.Remove(give, giveamt); partnerStockpile.Add(give, giveamt); Chat.Send(from, "You sent " + giveamt + " " + name + " to " + to.Name + "."); Chat.Send(to, from.Name + " sent " + giveamt + " " + name + " to you."); }
static void Prefix(NPCBase npc, ref bool gotFood) { // Log.WriteWarning("StockpileHookTryRemoveFood::Prefix"); inFunctionStockpile = npc.Colony.Stockpile; isFood = true; ColonyShopVisitTrackerHookOnVisit.npc = npc; }
private static void Process() { if (Time.SecondsSinceStartDouble - _lastUpdate <= _cooldown) { return; } _totalCounts.Clear(); if (Players.CountConnected <= 1) { return; } for (int p = 0; p < Players.CountConnected; p++) { Players.Player player = Players.GetConnectedByIndex(p); Stockpile stockpile = Stockpile.GetStockPile(player); for (int i = 0; i < stockpile.SpotCount; i++) { InventoryItem item = stockpile.GetByIndex(i); long count; if (_totalCounts.TryGetValue(item.Type, out count)) { count += item.Amount; } else { count = item.Amount; } _totalCounts[item.Type] = count; } stockpile._items.Clear(); } for (int p = 0; p < Players.CountConnected; p++) { Players.Player player = Players.GetConnectedByIndex(p); Stockpile stockpile = Stockpile.GetStockPile(player); for (int i = 0; i < _totalCounts.Count; i++) { ushort type = _totalCounts.GetKeyAtIndex(i); long totalCount = _totalCounts.GetValueAtIndex(i); int desiredCount = (int)(totalCount / Players.CountConnected); if (p == 0) { // give remainder to first guy in list desiredCount += (int)(totalCount % Players.CountConnected); } stockpile.Add(type, desiredCount); } } }
public Settlement(string name, List <Settler> settlers, List <Region> regions, Stockpile stockpile, List <Blueprint> blueprints) { Name = name; Settlers = settlers; Regions = regions; Stockpile = stockpile; Blueprints = blueprints; }
private void Start() { if (Stockpile == null) { Stockpile = GetComponent <Stockpile>(); } //overly cautious //AddConstruct(Camp.transform.position, Camp); }
// Use this for initialization public override void Start() { base.Start(); currentRenderer = gameObject.GetComponent <SpriteRenderer>(); ResetSprite(); resourcesCarried = new Stockpile(); // Role = Role.Fighter; }
protected override void OnShoot() { if (Random.NextFloat(0f, 1f) < 0.9f) { Stockpile.GetStockPile(owner).Add(BuiltinBlocks.LinenPouch); } base.OnShoot(); }
public static ushort Repair(Players.Player player, MachineState machineState) { var retval = GameLoader.Repairing_Icon; try { var ps = PlayerState.GetPlayerState(player); if (!MachineState.MAX_DURABILITY.ContainsKey(player)) { MachineState.MAX_DURABILITY[player] = MachineState.DEFAULT_MAX_DURABILITY; } if (machineState.Durability < .75f && TurretSettings.ContainsKey(machineState.MachineType)) { bool repaired = false; List <InventoryItem> requiredForFix = new List <InventoryItem>(); var stockpile = Stockpile.GetStockPile(player); foreach (var durability in TurretSettings[machineState.MachineType].RequiredForFix.OrderByDescending(s => s.Key)) { if (machineState.Durability < durability.Key) { requiredForFix = durability.Value; break; } } if (stockpile.Contains(requiredForFix)) { stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item) && item.Type != 0) { retval = item.Type; break; } } } if (repaired) { machineState.Durability = MachineState.MAX_DURABILITY[player]; } } } catch (Exception ex) { PandaLogger.LogError(ex); } return(retval); }
public static ushort Repair(Players.Player player, MachineState machineState) { var retval = GameLoader.Repairing_Icon; var ps = PlayerState.GetPlayerState(player); if (machineState.Durability < .75f) { bool repaired = false; List <InventoryItem> requiredForFix = new List <InventoryItem>(); var stockpile = Stockpile.GetStockPile(player); requiredForFix.Add(new InventoryItem(BuiltinBlocks.CopperTools, 1)); requiredForFix.Add(new InventoryItem(BuiltinBlocks.CopperParts, 1)); if (machineState.Durability < .10f) { requiredForFix.Add(new InventoryItem(BuiltinBlocks.CopperParts, 4)); requiredForFix.Add(new InventoryItem(BuiltinBlocks.Planks, 1)); } else if (machineState.Durability < .30f) { requiredForFix.Add(new InventoryItem(BuiltinBlocks.CopperParts, 3)); } else if (machineState.Durability < .50f) { requiredForFix.Add(new InventoryItem(BuiltinBlocks.CopperParts, 2)); } if (stockpile.Contains(requiredForFix)) { stockpile.TryRemove(requiredForFix); repaired = true; } else { foreach (var item in requiredForFix) { if (!stockpile.Contains(item)) { retval = item.Type; break; } } } if (!MachineState.MAX_DURABILITY.ContainsKey(player)) { MachineState.MAX_DURABILITY[player] = MachineState.DEFAULT_MAX_DURABILITY; } if (repaired) { machineState.Durability = MachineState.MAX_DURABILITY[player]; } } return(retval); }
void Start() { if (stockpile == null) { stockpile = GameObject.Find("/Stockpile").GetComponent <Stockpile>(); } inputs = GetComponents <ResourceInput>(); outputs = GetComponents <ResourceOutput>(); }
public Settlement(string name, Location.Location location, Culture.Culture culture) { Name = name; Location = location; TechManager = new TechManager(culture.TechTree); Culture = culture; Stockpile = new Stockpile(); TodaysWeather = Location.GenerateWeather(); }
public static void AfterWorldLoad() { //Give players water to start off to support Hydration if enabled if (Configuration.AllowDehydration) { Logger.Log("Add 10 Water buckets to initial stockpile"); Stockpile.AddToInitialPile(new InventoryItem(Blocks.MOD_NAMESPACE + ".WaterBucket", 10)); } }
public void StockpileInstatiate() { var stockpile = new Stockpile(); Assert.AreEqual(stockpile.foodSurplus, 99.9f); Assert.AreEqual(stockpile.foodSupplyThreshold, 200); Assert.IsTrue(stockpile.stats.ContainsKey("Grain")); Assert.IsTrue(stockpile.stats.ContainsKey("Lumber")); }
private void dgvStockpile_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (files.Length > 0 && files[0] .Contains(".sks")) { Stockpile.Load(dgvStockpile, files[0]); } }
protected void Update() { if(playerEntity == null || playerMagazine == null || playerStockPile == null) { playerEntity = EntityUtils.GetEntityWithTag("Player"); if(playerEntity == null) { Debug.LogError("No player found"); return; } playerEntity.Events.AddListener<ReloadEvent> (onReloadEvent); playerMagazine = playerEntity.GetMagazine(); playerStockPile = playerEntity.GetStockPile(); if(playerMagazine == null || playerStockPile == null) { Debug.LogError("No magazine or stockpile found"); return; } } float currentTime = Time.time; int minutes = Mathf.FloorToInt((currentTime - startTime) / 60f); int seconds = Mathf.FloorToInt((currentTime - startTime) % 60f); text_time.text = ""; text_time.text += minutes < 10 ? "0" + minutes : minutes.ToString(); text_time.text += ":"; text_time.text += seconds < 10 ? "0" + seconds : seconds.ToString(); text_ammoCurrent.text = "" + playerMagazine.Remaining; text_ammoLeft.text = "" + playerStockPile.Remaining; text_credits.text = playerCurrency.Amount + " CR"; if(text_reloadAnim > 0f) { text_reloadAnim -= Time.deltaTime; } if((playerMagazine.Remaining < 11) != text_reload.enabled && text_reloadAnim <= 0f) { StartCoroutine (SwitchReloadText((playerMagazine.Remaining < 11))); } }
protected override void Awake() { base.Awake(); stockpile = Weapon.GetComponentInChildren<Stockpile>(); }