public void WhenNtfSellTech(NetMessageStream msg) { string companyName = msg.ReadString().Trim(); string techName = msg.ReadString().Trim(); int price = msg.ReadInt32(); // 기술 상점 목록에 추가 SellingTech newTech = new SellingTech() { Seller = companyName, Name = techName, Price = price, }; this.TechStore.Add(newTech); }
public void WhenNtfSellProduct(NetMessageStream msg) { string companyName = msg.ReadString().Trim(); string productName = msg.ReadString().Trim(); int price = msg.ReadInt32(); // 제품 상점 목록에 추가 SellingTech newProduct = new SellingTech() { Seller = companyName, Name = productName, Price = price, }; this.ProductStore.Add(newProduct); }
private NetMessage WhenReqSellTech(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string companyName = msg.ReadData <string>().Trim(); string techName = msg.ReadData <string>().Trim(); int price = msg.ReadData <int>(); string targetUser = msg.ReadData <string>(); // 인증 var user = this.UserDirector.GetLoginUser(client.ID); if (user != null && user.Name == userName) { user = this.UserDirector.GetAccount(user.Name); var company = this.FindCompanyByName(companyName); // 유저가 존재하고 // 존재하는 회사가 유저의 소유이고 // 기술 이름이 유효하고 if (user != null && company != null && company.Owner == user.Name && techName.Length > 0) { Chip techChip = company.GetTech(techName); // 해당 기술이 회사에 존재하면 if (techChip != null) { // 판매 허가 및 기술 상점에 추가 SellingTech sellingTech = new SellingTech() { Name = techChip.Name, Price = price, Seller = company.Name, TargetUser = targetUser, Item = techChip.Clone(), }; m_techStore.Add(sellingTech); // 기술 판매 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(company.Name); writer.WriteData(techChip.Name); writer.WriteData(price); // 따로 허가된 유저가 있으면 if (targetUser.Length > 0) { // 판매자와 그 유저에게만 알림 this.NoticeWhereDelegate(new string[] { targetUser, user.Name }, writer.CreateMessage((int)MessageTypes.Ntf_SellTech)); } else { // 전체공개이면 그냥 모두에게 알림 this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_SellTech)); } } } } return(null); }
public void LoadAll() { m_companyList.Clear(); m_companySiteMap.Clear(); m_companySiteCount.Clear(); m_chipList.Clear(); m_chipPosMap.Clear(); m_chipMap.Clear(); m_techStore.Clear(); try { using (BinaryReader br = new BinaryReader(new FileStream(this.ServerPath + this.CompanyFileName, FileMode.Open))) { Version fileVersion = new Version(br.ReadString()); int companyCount = br.ReadInt32(); for (int i = 0; i < companyCount; ++i) { var company = new Company(); company.ReadFrom(br); m_companyList.Add(company); } int countX = br.ReadInt32(); for (int x = 0; x < countX; ++x) { int tileX = br.ReadInt32(); int countY = br.ReadInt32(); m_companySiteMap.Add(tileX, new Dictionary <int, string>()); var mapX = m_companySiteMap[tileX]; for (int y = 0; y < countY; ++y) { int tileY = br.ReadInt32(); string company = br.ReadString(); mapX.Add(tileY, company); this.AddCompanySiteCount(company, 1); } } int chipCount = br.ReadInt32(); for (int i = 0; i < chipCount; ++i) { Chip chip = new Chip(); chip.ReadFrom(br); int tileX = br.ReadInt32(); int tileY = br.ReadInt32(); this.AddChip(tileX, tileY, chip); } int techStoreSize = br.ReadInt32(); for (int i = 0; i < techStoreSize; ++i) { SellingTech tech = new SellingTech(); tech.ReadFrom(br); m_techStore.Add(tech); } int productStoreSize = br.ReadInt32(); for (int i = 0; i < productStoreSize; ++i) { SellingTech tech = new SellingTech(); tech.ReadFrom(br); m_productStore.Add(tech); } } } catch (FileNotFoundException) { } catch (EndOfStreamException) { } }
private NetMessage WhenReqBuyProduct(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string sellerName = msg.ReadData <string>().Trim(); string productName = msg.ReadData <string>().Trim(); int price = msg.ReadData <int>(); string buyerName = msg.ReadData <string>().Trim(); // 인증 var user = this.UserDirector.GetLoginUser(client.ID); if (user != null && user.Name == userName) { user = this.UserDirector.GetAccount(user.Name); var seller = this.FindCompanyByName(sellerName); var buyer = this.FindCompanyByName(buyerName); int maxProductCount = this.GetCompanySiteCount(buyer.Name) * GameValues.CompanyProductSizePerSite; // 유저가 존재하고 // 판매자가 존재하고 // 존재하는 구매자가 유저의 소유이고 여유공간이 있으면 // 제품 이름이 유효하고 if (user != null && seller != null && buyer != null && buyer.Owner == user.Name && buyer.ProductList.Count < maxProductCount && productName.Length > 0) { SellingTech sellingProduct = null; foreach (var product in m_productStore) { if (product.Name == productName && product.Seller == seller.Name && product.Price == price && (product.TargetUser.Length <= 0 || product.TargetUser == user.Name)) { sellingProduct = product; break; } } var sellerUser = this.UserDirector.GetAccount(seller.Owner); // 해당 제품이 구매자에게 판매중이며 // 판매처의 주인이 존재하면 if (sellingProduct != null && sellerUser != null) { // 상점에서 제거 m_productStore.Remove(sellingProduct); // 제품 구매 buyer.ProductList.Add(sellingProduct.Item.Clone()); // 가격만큼 차감 user.Resource -= sellingProduct.Price; // 가격만큼 입금 sellerUser.Resource += sellingProduct.Price; // 제품이 추가되었음을 알림 NetMessageStream addProductMsg = new NetMessageStream(); addProductMsg.WriteData(buyer.Name); addProductMsg.WriteData(sellingProduct.Name); client.Sender.SendMessage(addProductMsg.CreateMessage((int)MessageTypes.Rsp_ProduceProduct)); // 제품이 구매되어 상점에서 제거됨을 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(seller.Name); writer.WriteData(sellingProduct.Name); writer.WriteData(sellingProduct.Price); // 따로 허가된 유저가 있으면 if (sellingProduct.TargetUser.Length > 0) { // 판매자와 그 유저에게만 알림 this.NoticeWhereDelegate(new string[] { seller.Owner, sellingProduct.TargetUser }, writer.CreateMessage((int)MessageTypes.Ntf_BuyProduct)); } else { // 전체공개이면 그냥 모두에게 알림 this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_BuyProduct)); } } } } return(null); }
private NetMessage WhenReqSellProduct(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string companyName = msg.ReadData <string>().Trim(); int productIndex = msg.ReadData <int>(); int price = msg.ReadData <int>(); string targetUser = msg.ReadData <string>(); // 인증 var user = this.UserDirector.GetLoginUser(client.ID); if (user != null && user.Name == userName) { user = this.UserDirector.GetAccount(user.Name); var company = this.FindCompanyByName(companyName); // 유저가 존재하고 // 존재하는 회사가 유저의 소유이고 // 제품 번호가 유효하고 if (user != null && company != null && company.Owner == user.Name && productIndex >= 0) { Chip productChip = company.GetProductAt(productIndex); // 해당 제품이 회사에 존재하면 if (productChip != null) { // 판매 허가 및 제품 상점에 추가 SellingTech sellingProduct = new SellingTech() { Name = productChip.Name, Price = price, Seller = company.Name, TargetUser = targetUser, Item = productChip.Clone(), }; m_productStore.Add(sellingProduct); // 회사의 창고에서 제거 client.Sender.SendMessage(GetDiscardProductNotice(company.Name, productIndex)); // 제품 판매 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(company.Name); writer.WriteData(productChip.Name); writer.WriteData(price); // 따로 허가된 유저가 있으면 if (targetUser.Length > 0) { // 판매자와 그 유저에게만 알림 this.NoticeWhereDelegate(new string[] { targetUser, user.Name }, writer.CreateMessage((int)MessageTypes.Ntf_SellProduct)); } else { // 전체공개이면 그냥 모두에게 알림 this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_SellProduct)); } } } } return(null); }
private NetMessage WhenReqBuyTech(ServerVisitor client, NetMessageStream msg) { string userName = msg.ReadData <string>(); string sellerName = msg.ReadData <string>().Trim(); string techName = msg.ReadData <string>().Trim(); int price = msg.ReadData <int>(); string buyerName = msg.ReadData <string>().Trim(); // 인증 var user = this.UserDirector.GetLoginUser(client.ID); if (user != null && user.Name == userName) { user = this.UserDirector.GetAccount(user.Name); var seller = this.FindCompanyByName(sellerName); var buyer = this.FindCompanyByName(buyerName); int maxTechCount = this.GetCompanySiteCount(buyer.Name) * GameValues.CompanyTechSizePerSite; // 유저가 존재하고 // 판매자가 존재하고 // 존재하는 구매자가 유저의 소유이고 여유공간이 있으면 // 기술 이름이 유효하고 if (user != null && seller != null && buyer != null && buyer.Owner == user.Name && buyer.TechList.Count < maxTechCount && techName.Length > 0) { SellingTech sellingTech = null; foreach (var tech in m_techStore) { if (tech.Name == techName && tech.Seller == seller.Name && tech.Price == price && (tech.TargetUser.Length <= 0 || tech.TargetUser == user.Name)) { sellingTech = tech; break; } } var sellerUser = this.UserDirector.GetAccount(seller.Owner); // 해당 기술이 구매자에게 판매중이며 // 구매자가 해당 기술과 이름이 중복되는 기술을 가지고있지 않고 // 판매처의 주인이 존재하면 if (sellingTech != null && buyer.CheckTechOverlap(sellingTech.Item) == false && sellerUser != null) { // 상점에서 제거 m_techStore.Remove(sellingTech); // 기술 구매 buyer.TechList.Add(sellingTech.Item.Clone()); // 가격만큼 차감 user.Resource -= sellingTech.Price; // 가격만큼 입금 sellerUser.Resource += sellingTech.Price; // 기술이 추가되었음을 알림 client.Sender.SendMessage(this.GetNoticeDevelopTech(buyer.Name, sellingTech.Name, (int)DevelopTechResults.Success)); // 기술이 구매되어 상점에서 제거됨을 알림 NetMessageStream writer = new NetMessageStream(); writer.WriteData(seller.Name); writer.WriteData(sellingTech.Name); writer.WriteData(sellingTech.Price); // 따로 허가된 유저가 있으면 if (sellingTech.TargetUser.Length > 0) { // 판매자와 그 유저에게만 알림 this.NoticeWhereDelegate(new string[] { seller.Owner, sellingTech.TargetUser }, writer.CreateMessage((int)MessageTypes.Ntf_BuyTech)); } else { // 전체공개이면 그냥 모두에게 알림 this.NoticeDelegate(writer.CreateMessage((int)MessageTypes.Ntf_BuyTech)); } } } } return(null); }