/// <summary> /// 减少地块上的资源 /// </summary> /// <param name="vector"></param> /// <param name="type"></param> /// <param name="vector2"></param> /// <param name="mine">采集量</param> /// <returns>0为采集完毕</returns> public int ReduceResource(Vector3 vector, ResourceType.AttributionType type, Vector2Int vector2, int mine) { Vector3Int vector3Int = resMap.WorldToCell(vector); for (int i = 0; i < vector2.x; i++) { for (int j = 0; j < vector2.y; j++) { MapTile tile = map[vector3Int.x + i, vector3Int.y + j]; if (tile.isHasRes) { ResourceType resource = GameObject.FindObjectOfType <ResourceManage>().GetResourceInfo(tile.resName); if (resource.type == type) { if (tile.resAllowance < mine) { int Remnant = tile.resAllowance; tile.resAllowance = 0; tile.isHasRes = false; tile.resName = null; return(Remnant); } else { tile.resAllowance -= mine; return(mine); } } } } } return(0); }
/// <summary> /// 添加某项资源 /// </summary> /// <param name="data"></param> public void Add(ResourceType.AttributionType type, int num) { string resName = ""; switch (type) { case ResourceType.AttributionType.mineral: resName = "矿物"; break; case ResourceType.AttributionType.organicCompound: resName = "有机物"; break; default: return; } if (d_Resources.ContainsKey(resName)) { // d_Resources[d.Key] += d.Value; n_Resources[resName] += num; } else { // d_Resources.Add(d.Key, d.Value); n_Resources.Add(resName, num); } }
/// <summary> /// 按类型查询框选地块资源量 /// </summary> /// <param name="vector"></param> /// <param name="type"></param> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public int QueryResource(Vector3 vector, ResourceType.AttributionType type, int width, int height) { Vector3Int vector3Int = resMap.WorldToCell(vector); int num = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { MapTile tile = map[vector3Int.x + i, vector3Int.y + j]; if (tile.isHasRes) { ResourceType resource = GameObject.FindObjectOfType <ResourceManage>().GetResourceInfo(tile.resName); if (resource.type == type) { num += tile.resAllowance; } } } } return(num); }