private async Task OnUseFactionStorage(Player player)
        {
            await _gameServerConnection.RefreshFactionList();

            await player.RefreshInfo();

            lock (_saveState)
            {
                if ((player.MemberOfFaction != null))
                {
                    int factionId = player.MemberOfFaction.Id;

                    if (_factionStorageScreensOpen.Contains(factionId))
                    {
                        _traceSource.TraceInformation($"Player '{player}' can't use the shared storage because someone else is using it still.");
                        player.SendAlarmMessage("Another member of your faction has the storage window open.");
                    }
                    else
                    {
                        _factionStorageScreensOpen.Add(factionId);
                        _traceSource.TraceInformation($"Player '{player}' is now using the shared storage.");

                        if (!_saveState.FactionIdToItemStacks.ContainsKey(factionId))
                        {
                            _traceSource.TraceInformation($"Player '{player}' is now creating the shared storage as it didn't exist earlier.");
                            _saveState.FactionIdToItemStacks[factionId] = new ItemStacks();
                        }

                        var storage = _saveState.FactionIdToItemStacks[factionId];
                        var task    = player.DoItemExchange(
                            "Shared faction storage",
                            $"Items shared with the {player.MemberOfFaction.Name} faction",
                            "Process",
                            storage.ExtractOutForItemExchange());

                        task.ContinueWith(
                            (Task <Eleon.Modding.ItemExchangeInfo> itemExchangeInfoInTask) =>
                        {
                            lock (_saveState)
                            {
                                var itemExchangeInfoInQuote = itemExchangeInfoInTask.Result;
                                storage.AddStacks(new ItemStacks(itemExchangeInfoInQuote.items));
                                _factionStorageScreensOpen.Remove(factionId);
                                _saveState.Save(k_saveStateFilePath);
                                _traceSource.TraceInformation($"Player '{player}' is now done using the shared storage.");
                            }
                        });
                    }
                }
                else
                {
                    _traceSource.TraceInformation($"Player '{player}' is not in a faction");
                    player.SendAlarmMessage("You need to be in a faction to use shared faction storage.");
                }
            }
        }
        private async Task OnUseFactionStorage(Player player)
        {
            await _gameServerConnection.RefreshFactionList();

            await player.RefreshInfo();

            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(_fileStoragePath, "FactionArchive"));

            foreach (KeyValuePair <int, ItemStacks> storage in _saveState.FactionIdToItemStacks)
            {
                var items   = storage.Value.ToArray();
                var faction = _gameServerConnection.GetFaction(storage.Key);
                if (faction != null)
                {
                    //Eleon.Modding.FactionInfo factionInfo = new Eleon.Modding.FactionInfo(0, 111, "name", "AAA");
                    string factionArchiveFile = System.IO.Path.Combine(_fileStoragePath, "FactionArchive", $"{storage.Key}.txt");
                    using (var writer = System.IO.File.CreateText(factionArchiveFile))
                    {
                        int slot = 0;
                        await writer.WriteLineAsync($"FactionID ({storage.Key})...FactionInit ({faction.Initials})...FactionName ({faction.Name})");

                        await writer.WriteLineAsync($"Slot,ItemID,Count,Ammo,Decay,ItemName");

                        foreach (var anItem in items)
                        {
                            var itemName = "Unknown";
                            if (ServerConfigItems.ContainsKey(anItem.Id))
                            {
                                itemName = ServerConfigItems[anItem.Id].Name;
                            }
                            await writer.WriteLineAsync($"{slot},{anItem.Id},{anItem.Amount},{0},{0},{itemName}");

                            slot++;
                        }
                    }
                }
                else
                {
                    Console.WriteLine("*** Cannot locate Info for Faction: {0}", storage.Key);
                }
            }
            Console.WriteLine("Faction Storage Conversion complete");
        }
示例#3
0
        private async void CompleteTransaction(Player player, Configuration.ShipSeller.ShipInfo shipInfo)
        {
            // check money
            var credits = await player.GetCreditBalance();

            if (credits >= shipInfo.Price)
            {
                // deduct money
                await player.AddCredits(-shipInfo.Price);

                string shipName = string.Format(shipInfo.ShipNameFormat, player.Name);

                // make sure factionlist is up-to-date for player
                await _gameServerConnection.RefreshFactionList();

                var playerPosition = await player.GetCurrentPosition();

                // spawn ship
                await playerPosition.playfield.SpawnEntity(
                    shipName,
                    shipInfo.EntityType,
                    shipInfo.BlueprintName,
                    shipInfo.SpawnLocation.ToNumericsVector3(),
                    player);

                _traceSource.TraceInformation($"Player '{player}' bought {shipInfo.BlueprintName} named '{shipName}'");

                if (shipInfo.MessageToShowOnPurchase != null)
                {
                    await player.SendAlertMessage(shipInfo.MessageToShowOnPurchase);
                }
            }
            else
            {
                // something changed since they wanted to buy it...
                _traceSource.TraceEvent(TraceEventType.Error, 0, $"Player '{player}' suddenly doesn't have enough money (Price:{shipInfo.Price}). Balance: {credits}");
                await player.SendAlarmMessage("Insufficient funds!");
            }
        }