示例#1
0
 protected Source(Source <TObject, TBaseStatus> copyFrom, int?value = null, int?priority = null, SourceType?type = null)
 {
     if (copyFrom == null)
     {
         throw new ArgumentNullException("copyFrom");
     }
     Status             = copyFrom.Status;
     onChangedOverrides = copyFrom.onChangedOverrides;
     if (value == null)
     {
         internalValue = copyFrom.internalValue;
     }
     else
     {
         internalValue = value.Value;
     }
     if (priority == null)
     {
         Priority = copyFrom.Priority;
     }
     else
     {
         Priority = priority.Value;
     }
     if (type == null)
     {
         SourceType = copyFrom.SourceType;
     }
     else
     {
         SourceType = type.Value;
     }
 }
 public BaseStatusSystem()
 {
     requiredConversionChecks = new List <Action>();
     extraEnumTypes           = new List <Type>();
     DoNothing = (obj, status, ov, nv) => { };
     Total     = ints => {
         int total = 0;
         foreach (int i in ints)
         {
             total += i;
         }
         return(total);
     };
     Bool = ints => {
         int total = 0;
         foreach (int i in ints)
         {
             total += i;
         }
         if (total > 0)
         {
             return(1);
         }
         else
         {
             return(0);
         }
     };
     MaximumOrZero = ints => {
         int max = 0;
         foreach (int i in ints)
         {
             if (i > max)
             {
                 max = i;
             }
         }
         return(max);
     };
     defaultAggs = new Dictionary <SourceType, Func <IEnumerable <int>, int> >();
     defaultAggs[SourceType.Feed]     = Total;
     defaultAggs[SourceType.Suppress] = Bool;
     defaultAggs[SourceType.Prevent]  = Bool;
     valueAggs              = new DefaultValueDictionary <TBaseStatus, Aggregator>();
     SingleSource           = new DefaultHashSet <TBaseStatus>();
     statusesCancelledBy    = new MultiValueDictionary <TBaseStatus, TBaseStatus>();
     statusesExtendedBy     = new MultiValueDictionary <TBaseStatus, TBaseStatus>();
     statusesThatExtend     = new MultiValueDictionary <TBaseStatus, TBaseStatus>();
     statusesFedBy          = new Dictionary <SourceType, MultiValueDictionary <TBaseStatus, TBaseStatus> >();
     converters             = new Dictionary <SourceType, Dictionary <StatusPair <TBaseStatus>, Func <int, int> > >();
     cancellationConditions = new DefaultValueDictionary <StatusPair <TBaseStatus>, Func <int, bool> >();
     foreach (SourceType type in Enum.GetValues(typeof(SourceType)))
     {
         statusesFedBy[type] = new MultiValueDictionary <TBaseStatus, TBaseStatus>();
         converters[type]    = new Dictionary <StatusPair <TBaseStatus>, Func <int, int> >();
     }
     onChangedHandlers         = new DefaultValueDictionary <TBaseStatus, DefaultValueDictionary <StatusChange <TBaseStatus>, OnChangedHandler <TObject, TBaseStatus> > >();
     extraPreventionConditions = new MultiValueDictionary <TBaseStatus, Func <TObject, TBaseStatus, bool> >();
 }
示例#3
0
 void IHandlers <TObject> .SetHandler(TBaseStatus ignored, TBaseStatus overridden, bool increased, bool effect, OnChangedHandler <TObject> handler)
 {
     if (onChangedOverrides == null)
     {
         onChangedOverrides = new DefaultValueDictionary <StatusChange, OnChangedHandler <TObject> >();
     }
     onChangedOverrides[new StatusChange(overridden, increased, effect)] = handler;
 }
示例#4
0
        private static void DeserializeCurrentRaw(DefaultValueDictionary <TBaseStatus, int> dict, System.IO.BinaryReader reader)
        {
            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                int key   = reader.ReadInt32();
                int value = reader.ReadInt32();
                dict.Add(key, value);
            }
        }
示例#5
0
        private void SerializeCurrentRaw(InstanceType type, System.IO.BinaryWriter writer)
        {
            DefaultValueDictionary <TBaseStatus, int> dict = currentRaw[type];

            writer.Write(dict.Count);
            foreach (KeyValuePair <TBaseStatus, int> pair in dict)
            {
                writer.Write(pair.Key);
                writer.Write(pair.Value);
            }
        }
示例#6
0
		private static void CreateDefinitions(){
			defs = new DefaultValueDictionary<ItemType, ConsumableDefinition>();
			DefinePotion(ItemType.PotionOfHealing, 1);
			DefinePotion(ItemType.PotionOfRegeneration, 3);
			DefinePotion(ItemType.PotionOfStoneform, 1);
			DefinePotion(ItemType.PotionOfVampirism, 2);
			DefinePotion(ItemType.PotionOfBrutishStrength, 1);
			DefinePotion(ItemType.PotionOfRoots, 2);
			DefinePotion(ItemType.PotionOfHaste, 1);
			DefinePotion(ItemType.PotionOfSilence, 3);
			DefinePotion(ItemType.PotionOfCloaking, 1);
			DefinePotion(ItemType.PotionOfMysticMind, 1);

			DefineScroll(ItemType.ScrollOfBlinking, 1);
			DefineScroll(ItemType.ScrollOfPassage, 1);
			DefineScroll(ItemType.ScrollOfTime, 2);
			DefineScroll(ItemType.ScrollOfKnowledge, 1);
			DefineScroll(ItemType.ScrollOfSunlight, 3);
			DefineScroll(ItemType.ScrollOfDarkness, 3);
			DefineScroll(ItemType.ScrollOfRenewal, 2);
			DefineScroll(ItemType.ScrollOfCalling, 3);
			DefineScroll(ItemType.ScrollOfTrapClearing, 3);
			DefineScroll(ItemType.ScrollOfEnchantment, 7);
			DefineScroll(ItemType.ScrollOfThunderclap, 2);
			DefineScroll(ItemType.ScrollOfFireRing, 3);
			DefineScroll(ItemType.ScrollOfRage, 3);

			DefineOrb(ItemType.OrbOfFreezing, 1);
			DefineOrb(ItemType.OrbOfFlames, 1);
			DefineOrb(ItemType.OrbOfFog, 2);
			DefineOrb(ItemType.OrbOfDetonation, 2);
			DefineOrb(ItemType.OrbOfBreaching, 3);
			DefineOrb(ItemType.OrbOfShielding, 3);
			DefineOrb(ItemType.OrbOfTeleportal, 2);
			DefineOrb(ItemType.OrbOfPain, 2);
			DefineOrb(ItemType.OrbOfConfusion, 2);
			DefineOrb(ItemType.OrbOfBlades, 3);

			DefineWand(ItemType.WandOfDustStorm, 4, 2, 6);
			DefineWand(ItemType.WandOfInvisibility, 6, 2, 3);
			DefineWand(ItemType.WandOfFleshToFire, 6, 3, 6);
			DefineWand(ItemType.WandOfWebs, 4, 4, 9);
			DefineWand(ItemType.WandOfSlumber, 5, 2, 6);
			DefineWand(ItemType.WandOfReach, 6, 4, 7);
			DefineWand(ItemType.WandOfTelekinesis, 6, 2, 6);

			DefineOther(ItemType.RollOfBandages, 0, true, 5, 5);
			DefineOther(ItemType.FlintAndSteel, 0, true, 3, 3);
			DefineOther(ItemType.BlastFungus, 0, true, 0, 0);//todo check
			DefineOther(ItemType.MagicTrinket, 0);
		}
示例#7
0
        protected override bool Match(string requestUrl, out IDictionary <string, object> variables)
        {
            variables = new Dictionary <string, object>();

            int tempIndex = requestUrl.IndexOf("?");

            if (tempIndex > -1)
            {
                if (tempIndex > 0)
                {
                    requestUrl = requestUrl.Substring(0, tempIndex);
                }
                else
                {
                    requestUrl = string.Empty;
                }
            }
            if (!requestUrl.EndsWith("/"))
            {
                requestUrl += "/";
            }

            Regex routeRegex = new Regex(UrlRegexPattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            Match match      = routeRegex.Match(requestUrl);

            if (!match.Success)
            {
                return(false);
            }

            foreach (string item in RouteParameterList)
            {
                string value = match.Groups[item].Value.ToLower();
                if (string.IsNullOrEmpty(value) && DefaultValueDictionary.ContainsKey(item))
                {
                    value = DefaultValueDictionary[item].ToString();
                }
                variables.Add(item, value);
            }
            if (!variables.ContainsKey("controller"))
            {
                throw new HttpException("从当前路由中没有找到 controller.");
            }
            if (!variables.ContainsKey("action"))
            {
                throw new HttpException("从当前路由中没有找到 action.");
            }
            return(true);
        }
        public void ShouldWorkAsExpectedInNominalCase()
        {
            var dictionary = new DefaultValueDictionary<int, int>(new List<KeyValuePair<int, int>>
            {
                new KeyValuePair<int, int>(1, 1),
                new KeyValuePair<int, int>(2, 2),
                new KeyValuePair<int, int>(3, 3),
            });

            Assert.Equal(default(int), dictionary[0]);
            Assert.Equal(1, dictionary[1]);
            Assert.Equal(2, dictionary[2]);
            Assert.Equal(3, dictionary[3]);
            Assert.Equal(default(int), dictionary[4]);
        }
示例#9
0
        private static void CreateDefinitions()
        {
            defs = new DefaultValueDictionary <CreatureType, CreatureDefinition>();
            Define(MysteriousSpirit, 1);             // If something goes wrong, let's create one of these rather than crashing.
            defs.GetDefaultValue = () => defs[MysteriousSpirit];

            Define(Goblin, 10, CanOpenDoors, VulnerableToNeckSnap, LowLightVision)
            //todo: can spawn with item. is SpawnRule a whole different enum?
            .WithAiTraits(Aggressive, UnderstandsDoors)                     //todo, will any smaller ones like UnderstandsDoors be grouped together at all? Hazards, too...
            .WithAttack("fake attack but this would really specify damage and crit effect, if any");

            Define(Rat, 5, LowLightVision)
            .WithAiTraits(KeepsDistance)
            .WithAttack("todo");

            //and so on!
        }
示例#10
0
 internal StatusTracker(TObject obj, StatusSystem <TObject> rules)
 {
     this.obj   = obj;
     this.rules = rules;
     if (rules != null)
     {
         rules.TrackerCreated = true;
     }
     currentActualValues = new DefaultValueDictionary <TBaseStatus, int>();
     currentRaw          = new Dictionary <InstanceType, DefaultValueDictionary <TBaseStatus, int> >();
     statusInstances     = new Dictionary <InstanceType, MultiValueDictionary <TBaseStatus, StatusInstance <TObject> > >();
     internalFeeds       = new Dictionary <InstanceType, Dictionary <TBaseStatus, Dictionary <TBaseStatus, int> > >();
     changeStack         = new List <DefaultValueDictionary <StatusChange, OnChangedHandler <TObject> > >();
     foreach (InstanceType type in Enum.GetValues(typeof(InstanceType)))
     {
         currentRaw[type]      = new DefaultValueDictionary <TBaseStatus, int>();
         statusInstances[type] = new MultiValueDictionary <TBaseStatus, StatusInstance <TObject> >();
         internalFeeds[type]   = new Dictionary <TBaseStatus, Dictionary <TBaseStatus, int> >();
     }
 }
示例#11
0
 public LocalState(DefaultValueDictionary <LocalKey, TValue> dictionary)
     : this(dictionary, new DefaultValueDictionary <CaptureId, CapturedReferenceValue> (new CapturedReferenceValue()))
 {
 }
示例#12
0
 public LocalState(DefaultValueDictionary <LocalKey, TValue> dictionary, DefaultValueDictionary <CaptureId, CapturedReferenceValue> capturedReferences)
 {
     Dictionary         = dictionary;
     CapturedReferences = capturedReferences;
 }
示例#13
0
        public MainForm()
        {
            InitializeComponent();
            entSpawn = new EntitySpawner();

            hitby = new DefaultValueDictionary <Entity, bool>(false);

            double border = 40;

            Particle boxC  = (Particle)(new Vector <double>((double)ClientRectangle.Width / 2, (double)ClientRectangle.Height / 2));
            Particle boxR  = (Particle)(new Vector <double>((double)ClientRectangle.Width / 2 + border, (double)ClientRectangle.Height / 2 + border));
            Box      bgbox = new Box(boxR);

            EntityClass bgClass = new EntityClass("Background");

            bg = new Entity(0, boxC, bgbox, new GraphicsStyle(Brushes.Black), bgClass);

            bsm = new BulletStyleManager();
            InitializeBulletStyles();

            keyMan = new KeyManager();

            InitializeKeyManager();

            int vx = 1, vx2 = 2;
            int vy = 2, vy2 = 4;

            Drawable mchar = DrawableFactory.MakeCircle(8, new GraphicsStyle(Brushes.Orange, Pens.Red));

            game = new Game(new MainChar(mchar, bsm["MainChar"], ClientRectangle.Width / 2, ClientRectangle.Height - 20, 40));
            InitializePhysicsManager(game.PhysicsManager);
            InitializeRenderManager(game.RenderManager);

            Particle p1 = new Particle(x => vx * x, y => vy * y);
            Particle p2 = new Particle(Utils.MakeClosure <double, double, double>(ClientRectangle.Width, (w, x) => w - vx2 * x), y => vy2 * y);

            Particle q = new Particle(t => 7 * t + 10 * Utils.FastCos(t), t => 3 * t + 10 * Utils.FastSin(t));

            Ellipse entEl = new Ellipse(7);

            o1 = entEl.MakeDrawable(new GraphicsStyle(Brushes.Green));

            double FULL    = 2 * Math.PI;
            double cd      = 1;
            int    perCirc = 12;
            int    offsets = 6;

            BulletEmission[] bEms = new BulletEmission[offsets], bEms2 = new BulletEmission[offsets];
            double           DOWN = Math.PI / 2;

            // Makes the spiral pattern with bullets of shape o2
            Trajectory[][] arrs = new Trajectory[offsets][];
            for (int i = 0; i < offsets; i++)
            {
                arrs[i] = new Trajectory[perCirc];
            }
            for (int i = 0; i < perCirc; i++)
            {
                for (int j = 0; j < offsets; j++)
                {
                    arrs[j][i] = TrajectoryFactory.AngleMagVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 10);
                }
            }
            for (int i = 0; i < offsets; i++)
            {
                bEms[i] = new BulletEmission(cd, 0, arrs[i], bsm["OrangeRed_5"]);
            }
            // Same as above, but we're gonna change the shape
            for (int i = 0; i < offsets; i++)
            {
                arrs[i] = new Trajectory[perCirc];
            }
            for (int i = 0; i < perCirc; i++)
            {
                for (int j = 0; j < offsets; j++)
                {
                    arrs[j][i] = TrajectoryFactory.AngleMagVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 10);
                }
            }
            for (int i = 0; i < offsets; i++)
            {
                bEms2[i] = new BulletEmission(cd, 0, arrs[i], bsm["Azure_5"]);
            }
            // Same as above, but we're gonna change the shape again and the path
            BulletEmission[] bEms3 = new BulletEmission[offsets];
            for (int i = 0; i < offsets; i++)
            {
                arrs[i] = new Trajectory[perCirc];
            }
            for (int i = 0; i < perCirc; i++)
            {
                for (int j = 0; j < offsets; j++)
                {
                    arrs[j][i] = TrajectoryFactory.SpinningLinearAMVel((i * offsets + j) * (FULL / offsets / perCirc) + DOWN, 7 /*3*/, 0.5, 20);
                }
            }
            for (int i = 0; i < offsets; i++)
            {
                bEms3[i] = new BulletEmission(cd, 0, arrs[i], bsm["HotPink_5"]);
            }

            EntityClass enemyBullet = new EntityClass("EnemyBullet", "Bullet");
            EntityClass enemy       = new EntityClass("Enemy", "Character");

            BulletEmitter em  = new BulletEmitter(new BulletPattern(bEms, enemyBullet));
            BulletEmitter em2 = new BulletEmitter(new BulletPattern(bEms2, enemyBullet));
            BulletEmitter em3 = new BulletEmitter(new BulletPattern(bEms3, enemyBullet));

            entSpawn.MakeType("RedSpiral", null, o1, entEl, enemy, em);

            e  = entSpawn.Build("RedSpiral", 0, p1);
            e2 = entSpawn.Build("RedSpiral", 0, p2);

            Particle p3 = new Particle(x => 0.5 * x + 500, y => 3 * y);
            Entity   e3 = entSpawn.Build("RedSpiral", 0, p3);

            Particle p4 = new Particle(x => - 0.25 * x + 300, y => 3.5 * y);
            Entity   e4 = entSpawn.Build("RedSpiral", 0, p4);

            Particle p5 = new Particle(x => - 0.4 * x + 800, y => 2 * y);
            Entity   e5 = entSpawn.Build("RedSpiral", 0, p5);


            game += bg;
            game  = game + e + e2 + e3 + e4 + e5;

            entSpawn["WhiteSpiral"] = entSpawn["RedSpiral"].ChangeEmitter(em2, true);
            entSpawn["PinkWaves"]   = entSpawn["RedSpiral"].ChangeEmitter(em3, true);
            //entSpawn.MakeType("WhiteSpinningSpiral",null, o1, entEl, enemy, em2);

            Entity e6 = entSpawn.Build("WhiteSpiral", 0, q);

            game += e6;

            Particle r  = new Particle(Utils.MakeClosure <double, double, double>((double)ClientRectangle.Width / 3, (w, t) => w + 3 * t), t => 5 * t);
            Entity   e7 = entSpawn.Build("PinkWaves", 0, r);

            game += e7;
            game.ResetTime();
            BufferedGraphicsContext c = BufferedGraphicsManager.Current;

            buff = c.Allocate(CreateGraphics(), ClientRectangle);
        }
示例#14
0
 public LocalState(DefaultValueDictionary <LocalKey, TValue> dictionary) => Dictionary = dictionary;