Esempio n. 1
0
 /**
  * construct hull based on manifest
  */
 void Construct(HullManifest manifest)
 {
     this.manifest = manifest;
     foreach (ExternalModuleManifest extModManifest in manifest.modules)
     {
         HullSlot slot;
         if (!slots.TryGetValue(extModManifest.position, out slot))
         {
             slot = Instantiate(slotPrefab) as HullSlot;
             slot.transform.parent        = transform;
             slot.transform.localPosition = extModManifest.position;
             slots.Add(extModManifest.position, slot);
         }
         ExternalConstructionModule extMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.type)) as ExternalConstructionModule;
         extMod.transform.localRotation = extModManifest.rotation;
         extMod.stats         = extModManifest.stats;
         extMod.hitPointsLeft = extModManifest.hitPointsLeft;
         extMod.manifest      = extModManifest;
         Equip(extMod, slot);
         if (extMod is HullConstructionModule)
         {
             if (extModManifest.internalModule != null)
             {
                 InternalConstructionModule intMod = Instantiate(game.GetConstructionModulePrefab(extModManifest.internalModule.type)) as InternalConstructionModule;
                 intMod.stats         = extModManifest.internalModule.stats;
                 intMod.hitPointsLeft = extModManifest.internalModule.hitPointsLeft;
                 intMod.SetContents(extModManifest.internalModule.contents);
                 intMod.manifest = extModManifest.internalModule;
                 Equip(intMod, (HullConstructionModule)extMod);
             }
         }
     }
 }
Esempio n. 2
0
    public void Unequip(ExternalConstructionModule module)
    {
        if (module.hullSlot == null)
        {
            return;
        }
        if (module is HullConstructionModule)
        {
            if (((HullConstructionModule)module).internalModule != null)
            {
                return;
            }
            hullModules.Remove(module.hullSlot.transform.position);
        }
        else if (module is ThrusterConstructionModule)
        {
            thrust.thrusters.Remove((ThrusterConstructionModule)module);
        }
        else if (module is ManeuveringConstructionModule)
        {
            thrust.maneuverers.Remove((ManeuveringConstructionModule)module);
        }
        HullSlot slot = module.hullSlot;

        slot.module     = null;
        module.hullSlot = null;
        slot.Activate();
        slot.DeactivateAdjacents();
        module.OnUnequip();
        CalcBounds();
    }
Esempio n. 3
0
 /**
  * Wipe out everything
  */
 public void Clear()
 {
     // delete current stuff
     if (slots != null)
     {
         foreach (var pair in slots)
         {
             var slot = pair.Value;
             if (slot.module != null)
             {
                 ExternalConstructionModule extMod = slot.module;
                 if (slot.module is HullConstructionModule)
                 {
                     InternalConstructionModule intMod = ((HullConstructionModule)extMod).internalModule;
                     if (intMod != null)
                     {
                         Unequip(intMod);
                         Destroy(intMod.gameObject);
                     }
                 }
                 Unequip(extMod);
                 Destroy(extMod.gameObject);
             }
             Destroy(slot.gameObject);
         }
     }
     slots       = new Dictionary <Vector3, HullSlot>();
     hullModules = new Dictionary <Vector3, HullConstructionModule>();
 }
Esempio n. 4
0
 public void Unequip(ExternalConstructionModule module, HullSlot slot)
 {
     if (module.hullSlot != slot)
     {
         return;
     }
     Unequip(module);
 }
Esempio n. 5
0
    /**
     * Save state to manifest
     */
    public HullManifest CreateManifest()
    {
        HullManifest manifest = new HullManifest();

        manifest.position        = this.manifest.position;
        manifest.rotation        = this.manifest.rotation;
        manifest.velocity        = this.manifest.velocity;
        manifest.angularVelocity = this.manifest.angularVelocity;
        manifest.constellation   = this.manifest.constellation;
        manifest.star            = this.manifest.star;
        manifest.planet          = this.manifest.planet;
        foreach (KeyValuePair <Vector3, HullSlot> pair in slots)
        {
            // external module
            ExternalConstructionModule extMod = pair.Value.module;
            if (extMod == null)
            {
                continue;
            }
            ExternalModuleManifest extModManifest = new ExternalModuleManifest(
                extMod.hullSlot.transform.localPosition,
                extMod.transform.localRotation
                );
            extModManifest.name          = extMod.manifest.name;
            extModManifest.type          = (ModuleType)extMod.GetType().GetField("type").GetRawConstantValue();
            extModManifest.stats         = extMod.stats;
            extModManifest.hitPointsLeft = extMod.hitPointsLeft;

            // internal module
            manifest.modules.Add(extModManifest);
            if (extMod is HullConstructionModule)
            {
                InternalConstructionModule intMod = ((HullConstructionModule)extMod).internalModule;
                if (intMod != null)
                {
                    InternalModuleManifest intModManifest = new InternalModuleManifest(extMod.hullSlot);
                    intModManifest.name           = intMod.manifest.name;
                    intModManifest.type           = (ModuleType)intMod.GetType().GetField("type").GetRawConstantValue();
                    intModManifest.stats          = intMod.stats;
                    intModManifest.hitPointsLeft  = intMod.hitPointsLeft;
                    intModManifest.contents       = intMod.GetContents();
                    extModManifest.internalModule = intModManifest;
                }
            }
        }
        this.manifest = manifest;
        return(manifest);
    }
Esempio n. 6
0
 public void Equip(ExternalConstructionModule module, HullSlot slot)
 {
     if (module.hullSlot == slot)
     {
         module.transform.localPosition = Vector2.zero;
         return;
     }
     if (!slot.available)
     {
         return;
     }
     if (module.hullSlot != null)
     {
         Unequip(module);
     }
     slot.ActivateAdjacents();
     module.transform.parent        = slot.transform;
     module.transform.localPosition = Vector2.zero;
     slot.module     = module;
     module.hullSlot = slot;
     slot.Deactivate();
     inventory.RemoveModule(module);
     if (module is HullConstructionModule)
     {
         hullModules.Add(module.transform.position, (HullConstructionModule)module);
     }
     else if (module is ThrusterConstructionModule)
     {
         thrust.thrusters.Add((ThrusterConstructionModule)module);
     }
     else if (module is ManeuveringConstructionModule)
     {
         thrust.maneuverers.Add((ManeuveringConstructionModule)module);
     }
     module.OnEquip();
     CalcBounds();
 }