public void SetCurrentArea(AreaChangedEvent evt) { _currentArea = new Area() { Name = evt.Name, Type = evt.Type }; }
// Adding furniture to room. public void AddFurniture(Furniture newFurniture) { if (this.Area > newFurniture.Size) { _furniture.Add(newFurniture); this.Area -= newFurniture.Size; AreaChangedEvent?.Invoke(newFurniture.Size); notify($"New furniture has been added."); } else { notify($"You don't have enough space to add furniture."); } }
private ChatEvent ParseLine(string aline, bool isClientFileLine = true) { log.Trace($"Parsing line {aline} from {(isClientFileLine ? "Client file" : "Clipboard")}"); ChatEvent evt = null; bool processed = false; foreach (var line in new List <string> { aline }) { Offer offer = new Offer(); // Time if (isClientFileLine) { int timeIndex = line.IndexOf(" "); if (timeIndex == -1) { continue; } timeIndex = line.IndexOf(" ", timeIndex + 1); if (timeIndex == -1) { continue; } var strTime = line.Substring(0, timeIndex); if (string.IsNullOrEmpty(strTime) || string.IsNullOrWhiteSpace(strTime)) { continue; } DateTime date; if (!DateTime.TryParse(strTime.Replace("/", "-"), out date)) { continue; } offer.Time = date; } else { offer.Time = DateTime.Now; } // Player name bool alternatePlayerEndIndex = false; int playerStartIndex = line.IndexOf("@From "); if (playerStartIndex == -1) { playerStartIndex = line.IndexOf("@To "); if (playerStartIndex == -1) { playerStartIndex = line.IndexOf("@"); alternatePlayerEndIndex = true; if (playerStartIndex == -1) { continue; } } offer.IsOutgoing = true; playerStartIndex += 4; } else { playerStartIndex += 6; } int playerEndIndex = -1; playerEndIndex = line.IndexOf(alternatePlayerEndIndex ? " Hi" : ": ", playerStartIndex); if (playerEndIndex == -1) { continue; } offer.PlayerName = line.Substring(playerStartIndex, playerEndIndex - playerStartIndex); if (offer.PlayerName.IndexOf("<") != -1) { int nameIndex = offer.PlayerName.IndexOf(">"); if (nameIndex == -1) { continue; } offer.PlayerName = offer.PlayerName.Substring(nameIndex + 2); } // Item name int itemNameStartIndex = line.IndexOf(ITEM_NAME_START_WORD); if (itemNameStartIndex == -1) { continue; } itemNameStartIndex += ITEM_NAME_START_WORD.Length; int itemNameEndIndex = line.IndexOf(ITEM_NAME_END_WORD, itemNameStartIndex); bool alternateItemNameEndWord = false; if (itemNameEndIndex == -1) { itemNameEndIndex = line.IndexOf(ITEM_NAME_ALTERNATE_END_WORD, itemNameStartIndex); alternateItemNameEndWord = true; if (itemNameEndIndex == -1) { continue; } } offer.ItemName = line.Substring(itemNameStartIndex, itemNameEndIndex - itemNameStartIndex); // Price int priceStartIndex = itemNameEndIndex + (alternateItemNameEndWord ? ITEM_NAME_ALTERNATE_END_WORD : ITEM_NAME_END_WORD).Length; int priceEndIndex = line.IndexOf(" ", priceStartIndex); if (priceEndIndex == -1) { continue; } var value = line.Substring(priceStartIndex, priceEndIndex - priceStartIndex) .Trim() .Replace(".", ","); offer.Price = Convert.ToDouble(value); // Currency int currencyStartIndex = priceEndIndex + 1; int currencyEndIndex = line.IndexOf(CURRENCY_END_WORD, currencyStartIndex); if (currencyEndIndex == -1) { continue; } offer.Currency = line.Substring(currencyStartIndex, currencyEndIndex - currencyStartIndex); offer.CurrencyImageLink = AppService.Instance.GetCurrencyImageLink(offer.Currency); // League int leagueStartIndex = currencyEndIndex + CURRENCY_END_WORD.Length; int leagueEndIndex = line.IndexOf(" ", leagueStartIndex); if (leagueEndIndex == -1) { offer.League = line.Substring(leagueStartIndex); leagueEndIndex = leagueStartIndex + offer.League.Length; } else { offer.League = line.Substring(leagueStartIndex, leagueEndIndex - leagueStartIndex); } offer.League = Regex.Replace(offer.League, @"[0-9\.]", ""); var config = AppService.Instance.GetConfig(); if (config.AutoWhisperOutOfLeague && offer.League != config.CurrentLeague) { AppService.Instance.SendChatMessage($"@{offer.PlayerName} {AppService.Instance.ReplaceVars(config.OutOfLeagueWhisper, offer)}"); return(null); } // Item location int itemTabStartIndex = line.IndexOf("(stash tab \"", leagueEndIndex); int topEndIndex = -1; if (itemTabStartIndex != -1) { itemTabStartIndex += "(stash tab \"".Length; int itemTabEndIndex = line.IndexOf("\"; position: left ", itemTabStartIndex); if (itemTabEndIndex != -1) { offer.StashTab = line.Substring(itemTabStartIndex, itemTabEndIndex - itemTabStartIndex); int leftStartIndex = itemTabEndIndex + "\"; position: left ".Length; int leftEndIndex = line.IndexOf(", top ", leftStartIndex); if (leftEndIndex != -1) { int x = int.Parse(line.Substring(leftStartIndex, leftEndIndex - leftStartIndex)); int topStartIndex = leftEndIndex + ", top ".Length; topEndIndex = line.IndexOf(")", topStartIndex); if (topEndIndex != -1) { int y = int.Parse(line.Substring(topStartIndex, topEndIndex - topStartIndex)); ++topEndIndex; offer.Position = new System.Drawing.Point(x, y); } } } } // Aditionnal notes if ((topEndIndex != -1 && topEndIndex + 1 < line.Length) || (leagueEndIndex < line.Length)) { offer.Notes = line.Substring(topEndIndex == -1 ? leagueEndIndex : topEndIndex); } offer.Id = NextId(); evt = offer; processed = true; } if (!processed) { log.Trace("Line wasn't an offer, trying to parse has other events"); var line = aline.ToLower(); if (line.IndexOf(TRADE_ACCEPTED_MSG) != -1) { evt = new ChatEvent() { EvenType = Enums.ChatEventEnum.TradeAccepted }; } else if (line.IndexOf(TRADE_CANCELLED_MSG) != -1) { evt = new ChatEvent() { EvenType = Enums.ChatEventEnum.TradeCancelled }; } else if (line.IndexOf(PLAYER_JOINED_MSG) != -1) { var startIndex = aline.IndexOf("] : "); var endIndex = aline.IndexOf(PLAYER_JOINED_MSG); if (startIndex != -1 && endIndex != -1) { startIndex += "] : ".Length; evt = new JoinEvent(aline.Substring(startIndex, endIndex - startIndex)); } } else if (line.ToLower().IndexOf(AREA_JOINED) != -1) { string name = aline.Substring(line.IndexOf(AREA_JOINED) + AREA_JOINED.Length); name = name.Substring(0, name.Length - 1); name = Regex.Replace(name, " Level [0-9]+", ""); string type = name.ToLower().IndexOf("hideout") != -1 ? "Hideout" : "Unknown"; if (Areas.ContainsKey(name)) { name = Areas[name].Name; type = Areas[name].Type; } evt = new AreaChangedEvent() { EvenType = ChatEventEnum.AreaJoined, Name = name, Type = type }; } } return(evt); }