示例#1
0
        public override Component Create(JObject ammoObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D parentPos, float mod = 1)
        {
            try {
                string       id       = ammoObj.Value <string>("id");
                List <Color> colors   = Util.LoadColors(ammoObj.Value <JArray>("colors"));
                int          mass     = ammoObj.Value <int>("mass");
                int          damage   = (int)(ammoObj.Value <int>("damage") * mod);
                float        lifetime = ammoObj.Value <float>("lifetime") * mod;
                float        vel      = ammoObj.Value <float>("vel") * mod;
                float        maxVel   = ammoObj.Value <float>("maxVel") * mod;
                float        turnRate = ammoObj.Value <float>("turnRate") * mod;
                float        scale    = ammoObj.Value <float>("scale");
                JObject      shapeObj = ammoObj.Value <JObject>("shape");
                Shape        shape    = new ShapeFactory().Create(shapeObj, scale, parentPos);
                string       strategy = ammoObj.Value <string>("strategy");

                float primingDelay = 0;
                try { primingDelay = ammoObj.Value <float>("primingDelay"); }
                catch { }

                if (team == Team.Computer)
                {
                    colors = new List <Color> {
                        Color.Yellow
                    }
                }
                ;

                JArray emitterObj = null;
                try { emitterObj = ammoObj.Value <JArray>("emitters"); } catch { }

                Ammo result;

                if (emitterObj != null)
                {
                    List <Component> emitters = new EmitterFactory().CreateList(emitterObj, entHandler, boundaryStrat, team, parentPos, mod);
                    result = new EmittingAmmo(id, path, SwinGame.PointAt(0, 0), parentPos, shape, colors, mass, damage, lifetime, vel, maxVel, primingDelay, turnRate, emitters, boundaryStrat, entHandler, team);
                }
                else
                {
                    result = new Ammo(id, path, SwinGame.PointAt(0, 0), parentPos, shape, colors, mass, damage, lifetime, vel, maxVel, turnRate, boundaryStrat, team);
                }

                AIStrategyFactory aiStratFac = new AIStrategyFactory(0, 0);
                result.AIStrat = aiStratFac.CreateByName(strategy, result, entHandler);
                return(result);
            }
            catch (Exception e) {
                Console.WriteLine(e);
                return(null);
            }
        }
示例#2
0
        public override Component Create(JObject engineObj, string path, IHandlesEntities entHandler, BoundaryStrategy boundaryStrat, Team team, Point2D offsetPos, float mod = 1)
        {
            string  id       = engineObj.Value <string>("id");
            float   thrust   = engineObj.Value <float>("thrust") * mod;
            float   maxVel   = engineObj.Value <float>("maxVel") * mod;
            float   turnRate = engineObj.Value <float>("turnRate") * mod;
            int     mass     = engineObj.Value <int>("mass");
            int     health   = engineObj.Value <int>("health");
            float   scale    = engineObj.Value <float>("scale");
            JObject shapeObj = engineObj.Value <JObject>("shape");
            Shape   shape    = new ShapeFactory().Create(shapeObj, scale, offsetPos);

            JArray           emitterObj = engineObj.Value <JArray>("emitters");
            List <Component> emitters   = new EmitterFactory().CreateList(emitterObj, entHandler, boundaryStrat, team, offsetPos);

            Engine result = new Engine(id, path, SwinGame.PointAt(0, 0), offsetPos, shape,
                                       new List <Color> {
                Color.White
            }, health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1),
                                       boundaryStrat, team, emitters, thrust, maxVel, turnRate, mass);

            entHandler.Track(result);
            return(result);
        }