Ejemplo n.º 1
0
        public ActionResult Download(String id)
        {
            HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

            lock (HoloTableController._lockMap[id])
            {
                var model = new DetailModel(id);

                var js_handle = this.Request.Cookies["js_handle"];
                var handle = id;

                if (js_handle != null && !String.IsNullOrWhiteSpace(js_handle.Value))
                {
                    handle = js_handle.Value;
                }

                return File(model.GetBytes(), "application/xml", String.Format("{0}.xml", handle));
            }
        }
Ejemplo n.º 2
0
        public ShipLoadout(DetailModel model)
        {
            this.DisplayName = model.ShipJson.Name;

            this._weapons = model.View_CategoryLoadout[Items.CategoryEnum.Weapon]
                            .Where(s => s.GameData_Item != null)
                            .Select(s => s.GameData_Item)
                            .ToArray();
            this.Shields = model.View_CategoryLoadout[Items.CategoryEnum.Shield]
                           .Where(s => s.GameData_Item != null)
                           .Select(s => s.GameData_Item.Shields)
                           .ToArray();
            this.Armor = model.View_CategoryLoadout[Items.CategoryEnum.Armor]
                         .Where(s => s.GameData_Item != null)
                         .Select(s => s.GameData_Item)
                         .SelectMany(i => i.Armor.DamageMultipliers)
                         .FirstOrDefault();

            this.MinHealth = this._Flatten(model.GameData_Ship.Parts).Select(p => p.DamageMax).Where(d => d > 0).FirstOrDefault();
            this.MaxHealth = this._Flatten(model.GameData_Ship.Parts).Select(p => p.DamageMax).Sum();
        }
Ejemplo n.º 3
0
        public ShipLoadout(DetailModel model)
        {
            this.DisplayName = model.ShipJson.Name;

            this._weapons = model.View_CategoryLoadout[Items.CategoryEnum.Weapon]
                .Where(s => s.GameData_Item != null)
                .Select(s => s.GameData_Item)
                .ToArray();
            this.Shields = model.View_CategoryLoadout[Items.CategoryEnum.Shield]
                .Where(s => s.GameData_Item != null)
                .Select(s => s.GameData_Item.Shields)
                .ToArray();
            this.Armor = model.View_CategoryLoadout[Items.CategoryEnum.Armor]
                .Where(s => s.GameData_Item != null)
                .Select(s => s.GameData_Item)
                .SelectMany(i => i.Armor.DamageMultipliers)
                .FirstOrDefault();

            this.MinHealth = this._Flatten(model.GameData_Ship.Parts).Select(p => p.DamageMax).Where(d => d > 0).FirstOrDefault();
            this.MaxHealth = this._Flatten(model.GameData_Ship.Parts).Select(p => p.DamageMax).Sum();
        }
Ejemplo n.º 4
0
        public ActionResult Delete(String id)
        {
            if (String.Equals("sample", id, StringComparison.InvariantCultureIgnoreCase))
            {
                return RedirectToRoute("NotAllowed");
            }

            HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

            lock (HoloTableController._lockMap[id])
            {
                var model = new DetailModel(id);

                if (model != null)
                {
                    model.Delete();
                }
            }

            return View();
        }
Ejemplo n.º 5
0
        public ActionResult Hangar(String id)
        {
            try
            {
                HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

                lock (HoloTableController._lockMap[id])
                {
                    var model = new DetailModel(id);

                    ViewBag.ID = id;

                    return View(model);
                }
            }
            catch (FileNotFoundException)
            {
                Server.TransferRequest("/NotFound", true);
                return new EmptyResult { };
                return RedirectToRoute("NotFound", new { url = "NotFound" });
            }
        }
Ejemplo n.º 6
0
        private IEnumerable<Guid> FlattenIDs(DetailModel model, Item item)
        {
            if (item != null || item.ID != Guid.Empty)
            {
                yield return item.ID;

                if (item.Ports != null && item.Ports.Items != null)
                    foreach (var childID in item.Ports.Items.Where(i => i.ItemID != Guid.Empty).SelectMany(i => this.FlattenIDs(model, model.Inventory_ItemMap.GetValue(i.ItemID, null))))
                        yield return childID;
            }
        }
Ejemplo n.º 7
0
        public ActionResult Ship(String id, Guid shipID, Guid newID, Guid? parentID, String portName)
        {
            try
            {
                HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

                lock (HoloTableController._lockMap[id])
                {
                    var model = new DetailModel(id, shipID);

                    // Parents being equipped
                    var parentItems = model.Player.Items.Where(i => i.ID == parentID).ToArray();

                    // Ports being equipped
                    var newShipPorts = model.Player.Ships.Where(s => s.ID == shipID).Where(s => s.Ports != null).Where(s => s.Ports.Items != null).SelectMany(s => s.Ports.Items).Where(p => p.PortName == portName).ToArray();
                    var newItemPorts = model.Player.Items.Where(i => i.ID == parentID).Where(i => i.Ports != null).Where(i => i.Ports.Items != null).SelectMany(i => i.Ports.Items).Where(p => p.PortName == portName).ToArray();
                    var newPorts = newShipPorts.Concat(newItemPorts).ToArray();

                    // Item IDs being replaced
                    var oldItemIDs = new HashSet<Guid>(newPorts.Select(p => p.ItemID));

                    // Items being replaced
                    var oldItems = model.Player.Items.Where(i => oldItemIDs.Contains(i.ID)).ToArray();
                    var oldIDs = new HashSet<Guid>(oldItems.SelectMany(i => this.FlattenIDs(model, i)));

                    // Inventory being moved
                    var oldHangarInventory = model.Player.Inventory.Items.Where(i => oldIDs.Contains(i.ID));
                    var oldShipInventory = model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items.Where(i => oldIDs.Contains(i.ID)));
                    var oldInventory = oldShipInventory.Union(oldHangarInventory).ToArray();

                    // Items being equipped
                    var newItems = model.Player.Items.Where(i => i.ID == newID).ToArray();
                    var newIDs = new HashSet<Guid>(newItems.SelectMany(i => this.FlattenIDs(model, i)));

                    // Inventory being moved
                    var newHangarInventory = model.Player.Inventory.Items.Where(i => newIDs.Contains(i.ID));
                    var newShipInventory = model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items.Where(i => newIDs.Contains(i.ID)));
                    var newInventory = newShipInventory.Union(newHangarInventory).ToArray();

                    // Old ports
                    var oldShipPorts = model.Player.Ships.Where(s => s.Ports != null).Where(s => s.Ports.Items != null).SelectMany(s => s.Ports.Items).Where(p => p.ItemID == newID).Where(p => p.ItemID != Guid.Empty).ToArray();
                    var oldItemPorts = model.Player.Items.Where(i => i.Ports != null).Where(i => i.Ports.Items != null).SelectMany(i => i.Ports.Items).Where(p => p.ItemID == newID).Where(p => p.ItemID != Guid.Empty).ToArray();
                    var oldPorts = oldItemPorts.Concat(oldShipPorts).ToArray();

                    // Configure Ship inventory
                    foreach (var ship in model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null))
                    {
                        ship.Inventory.Items = ship.Inventory.Items.Where(i => !oldIDs.Contains(i.ID)).Where(i => !newIDs.Contains(i.ID)).ToArray();

                        if (ship.ID == shipID)
                        {
                            ship.Inventory.Items = ship.Inventory.Items.Union(newInventory).ToArray();
                        }
                    }

                    // Configure Player inventory
                    var shipItemIDs = new HashSet<Guid>(model.Player.Ships.Where(s => s.Inventory != null).Where(s => s.Inventory.Items != null).SelectMany(s => s.Inventory.Items).Select(i => i.ID));

                    model.Player.Inventory = new Inventory.Inventory
                    {
                        Items = model.Player.Items.Where(i => !shipItemIDs.Contains(i.ID)).Select(i => new Inventory.InventoryItem { ID = i.ID }).ToArray()
                    };

                    var oldPort = oldPorts.SingleOrDefault();

                    if (oldPort != null)
                    {
                        oldPort.ItemID = oldItemIDs.Distinct().SingleOrDefault();
                    }

                    var newPort = newPorts.SingleOrDefault();

                    if (newPort != null)
                    {
                        newPort.ItemID = newID;
                    }

                    foreach (var item in newItems)
                    {
                        if (item.Ports.Items == null) continue;
                        var gameItem = model.GameData_ItemMap[newID];
                        if (gameItem.Ports.Items == null) continue;
                        var itemPorts = item.Ports.Items.ToList();
                        var missingPorts = gameItem.Ports.Items.Where(p => !item.Ports.Items.Select(i => i.PortName).Distinct().Contains(p.Name));

                        foreach (var port in missingPorts)
                        {
                            itemPorts.Add(new Port
                            {
                                ItemID = Guid.Empty,
                                PortName = port.Name,
                            });
                        }

                        item.Ports.Items = itemPorts.ToArray();
                    }

                    // TODO: Validate parts - can't because CIG breaks the rules

                    // Set current ship (Optional)
                    model.Player.VehicleID = shipID;

                    model.Save();

                    ViewBag.ID = id;

                    return View(model);
                }
            }
            catch (FileNotFoundException)
            {
                this.Response.StatusCode = 500;
                this.Response.TrySkipIisCustomErrors = true;

                return new JsonResult
                {
                    Data = new
                    {
                        Reason = "Hangar Removed"
                    }
                };
            }
            catch (Exception ex)
            {
                Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(ex));

                this.Response.StatusCode = 500;
                this.Response.TrySkipIisCustomErrors = true;

                return new JsonResult
                {
                    Data = new
                    {
                        Reason = "System Error"
                    }
                };
            }
        }
Ejemplo n.º 8
0
        // http://holoxplor.ddrit.com/HoloTable/Rating/sample/00fa8108-001c-bff0-0000-000000000000
        // http://holoxplor.ddrit.com/HoloTable/Rating/sample/ANVL_Hornet_F7CM
        public ActionResult Rating(String id, String shipID)
        {
            Guid shipGuid = Guid.Empty;
            ShipLoadout loadout;

            if (Guid.TryParse(shipID, out shipGuid))
            {
                HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

                lock (HoloTableController._lockMap[id])
                {
                    DetailModel model = new DetailModel(id, shipGuid);

                    loadout = new ShipLoadout(model);
                }
            }
            else
            {
                loadout = new ShipLoadout(id);
            }

            return new ContentResult
            {
                Content = loadout.ToJSON(),
                ContentType = "application/json"
            };
        }
Ejemplo n.º 9
0
        public ActionResult Inventory(String id)
        {
            HoloTableController._lockMap[id] = HoloTableController._lockMap.GetValue(id, new Object());

            lock (HoloTableController._lockMap[id])
            {
                DetailModel model = new DetailModel(id);
                HashSet<String> currentItems = new HashSet<String>(model.GameData_ItemMap.Values.Where(i => i.ItemCategory != Items.CategoryEnum.__Unknown__).Select(k => k.Name).Distinct());

                return new ContentResult
                {

                    Content = new
                    {
                        Inventory = (from kvp in HoloXPLOR_App.Scripts.Items
                                     let name = kvp.Key
                                     let item = kvp.Value
                                     where currentItems.Contains(item.Name)
                                     select new
                                     {
                                         Name = name,
                                         Json = item,
                                     }).ToDictionary(k => k.Name, v => v.Json),
                        Ammo = (from kvp in HoloXPLOR_App.Scripts.Ammo
                                let name = kvp.Key
                                let ammo = kvp.Value
                                where ammo.ProjectileParams != null
                                where ammo.ProjectileParams.Length > 0
                                where (ammo.ProjectileParams[0] is GameData.BulletProjectileParams) ||
                                      (ammo.ProjectileParams[0] is GameData.RocketProjectileParams)
                                select new
                                {
                                    Name = name,
                                    Json = ammo.Json,
                                }).ToDictionary(k => k.Name, v => v.Json),
                        // Loadouts = HoloXPLOR_App.Scripts.Loadout.Where(l => HoloXPLOR_App.Scripts.Vehicles.GetValue(l.Key, null) != null).ToDictionary(k => k.Key, v => HoloXPLOR_App.Scripts.Vehicles.GetValue(v.Key, new Ships.Vehicle { }).DisplayName)
                        // Ship = Scripts.Vehicles.Values.GroupBy(g => g.Name).ToDictionary(k => k.Key, v => v.FirstOrDefault().DisplayName)
                    }.ToJSON(),
                    ContentType = "application/json"
                };
            }
        }