Esempio n. 1
0
        public async Task SaveNpcPreset(NpcPreset npcPreset)
        {
            if (npcPreset == null)
            {
                throw new ArgumentNullException("npcPreset");
            }

            await _presetRepository.SaveAsync(npcPreset);
        }
Esempio n. 2
0
        public async Task ViewPresetInfo(string name)
        {
            var dmChannel = await Context.User.GetOrCreateDMChannelAsync();

            NpcPreset preset = await _presetService.GetNpcPreset(name);

            if (preset == null)
            {
                await dmChannel.SendMessageAsync(String.Format(Messages.ERR_NPC_PRESET_NOT_FOUND, name));
            }

            StringBuilder sb = new StringBuilder();

            foreach (var stat in preset.Statistics)
            {
                sb.Append($"{stat.Statistic.Name}: {stat.Value}\n");
            }

            await dmChannel.SendMessageAsync(Context.User.Mention, embed : EmbedHelper.BuildBasicEmbed($"Preset info for {preset.Name}:", sb.ToString()));
        }
Esempio n. 3
0
        public async Task <bool> CreateNpcPresetAsync(string name)
        {
            // NPC preset with name exists
            if (await GetNpcPreset(name) != null)
            {
                throw new Exception(Exceptions.NPC_PRESET_EXISTS);
            }

            NpcPreset preset = new NpcPreset
            {
                Name       = name,
                Statistics = new List <StatisticValue>()
            };

            _statsService.InitializeStatistics(preset.Statistics);

            await _presetRepository.AddAsync(preset);

            return(true);
        }
Esempio n. 4
0
        public Character CreateNpc(string name, NpcPreset preset)
        {
            if (FindNpc(name) != null)
            {
                throw new Exception(Exceptions.NPC_CHAR_EXISTS);
            }

            if (preset == null)
            {
                throw new Exception(Exceptions.NPC_INVALID_PRESET);
            }
            if (preset.Enabled == false)
            {
                throw new Exception(Exceptions.NPC_INVALID_PRESET_DISABLED);
            }

            Character newNpc = new Character {
                Name = name, Statistics = preset.Statistics
            };

            // Trying to keep this OOP as possible...

            _statService.InitializeStatistics(newNpc.Statistics);

            var timer = new Timer();

            timer.Elapsed += (sender, e) => OnDurationElasped(sender, e, newNpc);
            timer.Interval = NPC_ACTIVE_DURATION.TotalMilliseconds;
            timer.Enabled  = true;

            NpcTimers.Add(newNpc, timer);

            Npcs.Add(newNpc);

            return(newNpc);
        }