示例#1
0
        public static void AddBuff(this Player player, string buffname, int duration = 2)
        {
            buffname = buffname.ToLower();
            int id = VPlayer.GetData(player).GlobalID;

            if (AllPlayerBuffers.TryGetValue(id, out Dictionary <string, int> map))
            {
                if (!map.ContainsKey(buffname))
                {
                    int       vanilla = TranslateVanilla(buffname);
                    VitriBuff vitri   = TranslateVitri(buffname);

                    if ((vanilla != -1 && !player.buffImmune[vanilla])
                        ||
                        (vitri != null && !player.buffImmune[vitri.Type]))
                    {
                        map.Add(buffname, duration);
                    }
                }

                return;
            }

            throw new KeyNotFoundException($"Error in BuffCache.AddBuff: '{player.name}' was not given a buff cache!");
        }
示例#2
0
        internal static void ApplyAllBuffs()
        {
            // Add cached projectile buffs to their owner
            for (int i = 0; i < Main.projectile.Length; i++)
            {
                if (Main.projectile[i].active && Main.projectile[i].minion)
                {
                    ProjCache.GetData(Main.projectile[i]).ApplyBuffs();
                }
            }

            // Then activate both npcs and players together
            for (int i = 0; i < Main.npc.Length; i++)
            {
                if (i < 255 && Main.player[i].active)
                {
                    int pid = VPlayer.GetData(Main.player[i]).GlobalID;
                    if (AllPlayerBuffers.TryGetValue(pid, out Dictionary <string, int> pbuffer) &&
                        AllPlayerBuffs.TryGetValue(pid, out Dictionary <string, int> playerbuffs))
                    {
                        playerbuffs.Clear();
                        playerbuffs.AddRange(pbuffer);
                        pbuffer.Clear();

                        if (!Main.player[i].dead && !Main.player[i].ghost)
                        {
                            foreach ((string buff, int duration) in playerbuffs)
                            {
                                int vanilla = TranslateVanilla(buff);
                                Main.player[i].AddBuff(vanilla != -1 ? vanilla : TranslateVitri(buff).Type, duration);
                            }
                        }
                    }
                }

                if (Main.npc[i].active)
                {
                    int nid = VNPC.GetData(Main.npc[i]).GlobalID;
                    if (AllNPCBuffers.TryGetValue(nid, out Dictionary <string, int> nbuffer) &&
                        AllNPCBuffs.TryGetValue(nid, out Dictionary <string, int> npcbuffs))
                    {
                        npcbuffs.Clear();
                        npcbuffs.AddRange(nbuffer);
                        nbuffer.Clear();

                        foreach ((string buff, int duration) in npcbuffs)
                        {
                            int vanilla = TranslateVanilla(buff);
                            Main.npc[i].AddBuff(vanilla != -1 ? vanilla : TranslateVitri(buff).Type, duration);
                        }
                    }
                }
            }
        }
示例#3
0
        internal static int ReservePlayer()
        {
            int id;

            do
            {
                if (NextPlayerID == int.MaxValue)
                {
                    NextPlayerID = int.MinValue;
                }

                id = NextPlayerID;
                NextPlayerID++;
            }while (!AllPlayerBuffs.TryAdd(id, new Dictionary <string, int>()));
            AllPlayerBuffers.Add(id, new Dictionary <string, int>());
            return(id);
        }
示例#4
0
        public static bool HasBuff(this Player player, string buffname)
        {
            buffname = buffname.ToLower();
            int id = VPlayer.GetData(player).GlobalID;

            if (AllPlayerBuffs.TryGetValue(id, out Dictionary <string, int> map))
            {
                return(map.ContainsKey(buffname));
            }

            if (AllPlayerBuffers.TryGetValue(id, out Dictionary <string, int> map2))
            {
                return(map2.ContainsKey(buffname));
            }

            return(false);
        }
示例#5
0
 internal static void DeletePlayer(int globalID)
 {
     AllPlayerBuffers.Remove(globalID);
     AllPlayerBuffs.Remove(globalID);
 }