using Google.Protobuf.WellKnownTypes; using ServerCommon; using USER_GUID = System.String; using BEACON_GUID = System.String; using META_ID = System.UInt32; using ServerCore; using ServerBase; using static ServerMessage.Types; namespace GameServer { internal static class BeaconShopHelper { public static async Task DeactiveBeaconShopItems(string beaconGuid) { var server_logic = GameServerApp.getServerLogic(); var dynamo_db_client = server_logic.getDynamoDbClient(); var (result, primary_key_object) = await DynamoDBDocBaseHelper.makePrimaryKey(beaconGuid); if (result.isFail() || primary_key_object == null) { return result; } var query_config = dynamo_db_client.makeQueryConfigForReadByPKOnly(primary_key_object.PK); (result, var read_docs) = await dynamo_db_client.simpleQueryDocTypesWithQueryOperationConfig(query_config); if (result.isFail()) { return result; } foreach (var beacon_shop_item_doc in read_docs) { var beaconShopItemAttrib = beacon_shop_item_doc.getAttrib(); NullReferenceCheckHelper.throwIfNull(beaconShopItemAttrib, () => $"beaconShopItemAttrib is null !!"); beaconShopItemAttrib.IsActiveSelling = false; beacon_shop_item_doc.setQueryType(QueryType.Update); result = await dynamo_db_client.simpleUpdateDocumentWithDocType(beacon_shop_item_doc); if (result.isFail()) { return result; } } return result; } public static BeaconShopItemBoardInfo toBeaconShopItemMongoDataClient(this BeaconShopMongoDoc beaconShopMongoDoc) { var beacon_shop_4_client = new BeaconShopItemBoardInfo(); beacon_shop_4_client.ItemGuid = beaconShopMongoDoc.ItemGuid; beacon_shop_4_client.ItemMetaid = (int)beaconShopMongoDoc.TagId; beacon_shop_4_client.BeaconGuid = beaconShopMongoDoc.BeaconGuid; beacon_shop_4_client.BeaconNickName = beaconShopMongoDoc.BeaconNickName; beacon_shop_4_client.BeaconTitle = beaconShopMongoDoc.BeaconTitle; beacon_shop_4_client.BeaconBodyItemMetaId = beaconShopMongoDoc.BeaconBodyItemMetaId; beacon_shop_4_client.PriceForUnit = beaconShopMongoDoc.PriceForUnit; beacon_shop_4_client.Amount = beaconShopMongoDoc.Amount; beacon_shop_4_client.OwnerGuid = beaconShopMongoDoc.OwnerGuid; beacon_shop_4_client.OwnerNickName = beaconShopMongoDoc.OwnerNickName; beacon_shop_4_client.BeaconMyHomeGuid = beaconShopMongoDoc.BeaconMyHomeGuid; beacon_shop_4_client.SellingFinishTime = Timestamp.FromDateTime(beaconShopMongoDoc.SellingFinishTime); return beacon_shop_4_client; } public async static Task CreateBeaconShopSoldRecord(BeaconShopItemAttribute beaconShopItemAttribute, string buyerNickName, int amount, double soldPrice, double taxPrice, double givenPrice) { DateTime now = DateTimeHelper.Current; var beacon_shop_sold_record_doc = new BeaconShopSoldRecordDoc(beaconShopItemAttribute.UserGuid, now); var beacon_shop_sold_record_attrib = beacon_shop_sold_record_doc.getAttrib(); if (beacon_shop_sold_record_attrib == null) { return null; } beacon_shop_sold_record_attrib.UserGuid = beaconShopItemAttribute.UserGuid; beacon_shop_sold_record_attrib.BeaconGuid = beaconShopItemAttribute.BeaconGuid; beacon_shop_sold_record_attrib.ItemMetaId = beaconShopItemAttribute.ItemMetaId; beacon_shop_sold_record_attrib.BuyerNickName = buyerNickName; beacon_shop_sold_record_attrib.PriceForUnit = beaconShopItemAttribute.PriceForUnit; beacon_shop_sold_record_attrib.Amount = amount; beacon_shop_sold_record_attrib.SalesTime = now; beacon_shop_sold_record_attrib.SoldPrice = soldPrice; beacon_shop_sold_record_attrib.TaxPrice = taxPrice; beacon_shop_sold_record_attrib.GivenPrice = givenPrice; var result = await beacon_shop_sold_record_doc.newDoc4Query(); if (result.isFail()) { return null; } return beacon_shop_sold_record_doc; } public static void send_GS2GS_NTF_UPDATE_SOLD_RECORD(string targetServer, USER_GUID targetUserGuid) { ConditionValidCheckHelper.throwIfFalseWithCondition(() => true != targetServer.isNullOrWhiteSpace() , () => $"targetServer is NullOrWhiteSpace !!! - targetServer:{targetServer}, targetUserGuid:{targetUserGuid}"); var server_logic = GameServerApp.getServerLogic(); var rabbit_mq_4_game = server_logic.getRabbitMqConnector() as RabbitMQ4Game; NullReferenceCheckHelper.throwIfNull(rabbit_mq_4_game, () => $"rabbit_mq_4_game is null !!"); var ntf_packet = new ServerMessage(); var ntf_update_sold_record = new GS2GS_NTF_UPDATE_SOLD_RECORD(); ntf_packet.NtfUpdateSoldRecord = ntf_update_sold_record; ntf_update_sold_record.TargetUserGuid = targetUserGuid; rabbit_mq_4_game.SendMessage(targetServer, ntf_packet); } public static void send_GS2GS_NTF_UPDATE_BEACON_SHOP_ITEM(USER_GUID targetUserGuid, BEACON_GUID targetBeaconGuid, bool hasBeaconShopItem) { var server_logic = GameServerApp.getServerLogic(); var rabbit_mq_4_game = server_logic.getRabbitMqConnector() as RabbitMQ4Game; NullReferenceCheckHelper.throwIfNull(rabbit_mq_4_game, () => $"rabbit_mq_4_game is null !!"); var ntf_packet = new ServerMessage(); var ntf_update_beacon_shop_item = new GS2GS_NTF_UPDATE_BEACON_SHOP_ITEM(); ntf_packet.NtfUpdateBeaconShopItem = ntf_update_beacon_shop_item; ntf_update_beacon_shop_item.TargetUserGuid = targetUserGuid; ntf_update_beacon_shop_item.TargetBeaconGuid = targetBeaconGuid; ntf_update_beacon_shop_item.HasBeaconShopItem = hasBeaconShopItem == true ? BoolType.True : BoolType.False; rabbit_mq_4_game.sendMessageToExchangeAllGame(ntf_packet); } public static ItemDoc toItemDocFromBeaconShopItemDoc(BeaconShopItemDoc beaconShopItemDoc, ushort itemStackCount) { var beacon_shop_item_attrib = beaconShopItemDoc.getAttrib(); NullReferenceCheckHelper.throwIfNull(beacon_shop_item_attrib, () => $"beacon_shop_item_attrib is null !!"); var item_guid = Guid.NewGuid().ToString("N"); var itemDoc = new ItemDoc(beacon_shop_item_attrib.OwnerEntityType, beacon_shop_item_attrib.UserGuid, item_guid); var item_attrib = itemDoc.getAttrib(); NullReferenceCheckHelper.throwIfNull(item_attrib, () => $"item_attrib is null !!!"); item_attrib.ItemMetaId = beacon_shop_item_attrib.ItemMetaId; item_attrib.ItemStackCount = itemStackCount; item_attrib.Level = beacon_shop_item_attrib.Level; item_attrib.Attributes = beacon_shop_item_attrib.Attributes.Select(x => x).ToList(); item_attrib.EquipedInvenType = beacon_shop_item_attrib.EquipedInvenType; item_attrib.EquipedPos = beacon_shop_item_attrib.EquipedPos; return itemDoc; } } }