public void SetResource(Resource resource, int value, bool silent) { if (!silent) { OnResourceChanged?.Invoke(resource, int.MaxValue, int.MaxValue); } }
private void ValuesChanged() { _preventsMove = false; _preventsAction = false; var enumerator = _keys.GetEnumerator(); try { while (enumerator.MoveNext()) { if (enumerator.Current.Value.PreventsMove) { _preventsMove = true; } if (enumerator.Current.Value.PreventsAction) { _preventsAction = true; } if (_preventsAction && _preventsMove) { break; } } } finally { enumerator.Dispose(); } OnResourceChanged.SafeInvoke(); }
public void SetResource(Resource resource, int value, bool silent) { if (!_resources.ContainsKey(resource)) { if (_resources != null) { _resources.Add(resource, value); if (!silent) { OnResourceChanged?.Invoke(resource, 0, _resources[resource]); } } else { throw new ArgumentException("Tried to spend a null resource."); } } else { int before = _resources[resource]; _resources[resource] = value; if (!silent) { OnResourceChanged?.Invoke(resource, before, _resources[resource]); } } }
public void Update() { var temp = Meat; Meat = Mathf.Min(Meat, StorageMaxCapacity); if (temp != Meat) { OnResourceChanged?.Invoke(ResourceTypes.Meat, Meat); } temp = Fruit; Fruit = Mathf.Min(Fruit, StorageMaxCapacity); if (temp != Fruit) { OnResourceChanged?.Invoke(ResourceTypes.Fruit, Fruit); } }
public void Store(ResourceTypes type, int quantity) { switch (type) { case ResourceTypes.Meat: Meat = Mathf.Min(Meat + quantity, StorageMaxCapacity); OnResourceChanged?.Invoke(ResourceTypes.Meat, Meat); break; case ResourceTypes.Fruit: Fruit = Mathf.Min(Fruit + quantity, StorageMaxCapacity); OnResourceChanged?.Invoke(ResourceTypes.Fruit, Fruit); break; default: throw new System.Exception("There is no such resource in manager: " + type); } }
// 作弊代码 void OnCheatCodeMsg(IReadableBuffer data) { var code = data.ReadString(); switch (code) { case "ShowMeTheMoney": { var uid = data.ReadString(); var num = data.ReadInt(); var p = GetNoByUser(uid); var money = Players[p].Resources["Money"]; money += num; Players[p].Resources["Money"] = money; OnResourceChanged.SC(p, "Money", money); } break; default: throw new Exception("do not support any cheat code yet"); } }
public bool Spend(ResourceTypes type, int quantity) { if (IsEnough(type, quantity)) { switch (type) { case ResourceTypes.Meat: Meat -= quantity; OnResourceChanged?.Invoke(ResourceTypes.Meat, Meat); return(true); case ResourceTypes.Fruit: Fruit -= quantity; OnResourceChanged?.Invoke(ResourceTypes.Fruit, Fruit); return(true); default: throw new System.Exception("There is no such resource in manager: " + type); } } Debug.Log("Not enough resources: " + type); return(false); }
// 增加指定资源 protected override void NotifyResourceChanged(int p, string resourceType, Fix64 delta, Fix64 total) { OnResourceChanged.SC(p, resourceType, total); }
public void ResourceChanged(string resourceName) { OnResourceChanged?.Invoke(resourceName); }