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); } }
private AIShip CreateAIShip(string shipId, Point2D pos, BoundaryStrategy boundaryStrat, Difficulty diff, IHandlesEntities entHandler) { AIStrategyFactory strategyFac = new AIStrategyFactory(diff.DifficultyLevel, diff.ShootCooldown); JObject obj = Util.Deserialize(FileRegistry[shipId]); //int health = obj.Value<int>("health"); List <Color> shipColors = new List <Color> { Color.Crimson, Color.Yellow, Color.White, Color.Red }; float scale = obj.Value <float>("scale"); JArray enginesObj = obj.Value <JArray>("engines"); JArray toolsObj = obj.Value <JArray>("tools"); JArray emittersObj = obj.Value <JArray>("emitters"); JObject shapeObj = obj.Value <JObject>("shape"); Team team = Team.Computer; Point2D offset = SwinGame.PointAt(0, 0); //shape Shape shape = new ShapeFactory().Create(shapeObj, scale, SwinGame.PointAt(0, 0)); int health = shape.Mass / 2; shape.TeleportTo(pos); //components List <Component> components = BuildComponents(enginesObj, toolsObj, emittersObj, entHandler, boundaryStrat, team, offset, diff.AIMod); //build and return ship AIShip result = new AIShip(shipId, FileRegistry[shipId], pos, SwinGame.PointAt(0, 0), shape, shipColors, health, SwinGame.VectorTo(0, 0), SwinGame.VectorTo(0, -1), boundaryStrat, team, components); //create strategy AIStrategy aiStrat = strategyFac.Create((IAIEntity)result, entHandler); result.AIStrategy = aiStrat; result.TeleportTo(pos); return(result); }