Ejemplo n.º 1
0
 /// <summary>
 /// Populates the container based on what is linked to the objInt
 /// </summary>
 /// <param name="cn">Cn.</param>
 /// <param name="objInt">Object int.</param>
 public static void PopulateContainer(Container cn, ObjectInteraction objInt, ObjectLoader objList)
 {
     //cn.ObjectsAccepted=-1;//For now default to accept all
     cn.Capacity = 40;
     for (int i = 0; i <= cn.MaxCapacity(); i++)
     {                        //init the variables.
         if (cn.items[i] == null)
         {
             cn.items[i] = "";
         }
     }
     if (objInt.link != 0)                           //Container has objects
     {
         ObjectLoaderInfo tmpobj = ObjectLoader.getObjectInfoAt(objInt.link, objList);
         //int count = 0;
         if (ObjectLoader.GetItemTypeAt(objInt.link, objList) != ObjectInteraction.LOCK)
         {
             cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj));
         }
         while (tmpobj.next != 0)
         {
             tmpobj = ObjectLoader.getObjectInfoAt((int)tmpobj.next, objList);                                        //objList[tmpobj.next];
             cn.AddItemToContainer(ObjectLoader.UniqueObjectName(tmpobj));
         }
     }
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Creates the fish that the player has caught.
    /// </summary>
    /// <returns>The fish.</returns>
    ObjectInteraction CreateFish()
    {
        ObjectLoaderInfo  newobjt = ObjectLoader.newObject(182, 40, 0, 1, 256);
        ObjectInteraction fishy   = ObjectInteraction.CreateNewObject(CurrentTileMap(), newobjt, CurrentObjectList().objInfo, GameWorldController.instance.InventoryMarker.gameObject, GameWorldController.instance.InventoryMarker.transform.position);

        fishy.gameObject.name = ObjectLoader.UniqueObjectName(newobjt);
        fishy.isquant         = 1;
        GameWorldController.MoveToInventory(fishy.gameObject);
        return(fishy);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Creates the fish that the player has caught.
    /// </summary>
    /// <returns>The fish.</returns>
    GameObject CreateFish()
    {
        ObjectLoaderInfo newobjt = ObjectLoader.newObject(182, 40, 0, 1, 256);
        GameObject       fishy   = ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(), newobjt, GameWorldController.instance.InventoryMarker.gameObject, GameWorldController.instance.InventoryMarker.transform.position).gameObject;

        fishy.name = ObjectLoader.UniqueObjectName(newobjt);
        GameWorldController.MoveToInventory(fishy);
        //newobjt.index= UWCharacter.Instance.playerInventory.ItemCounter++;

        //fishy.GetComponent<Food>().Nutrition=5;
        return(fishy);       // ObjectInteraction.CreateNewObject(182).gameObject;
    }
    public GameObject CloneObject(ObjectInteraction objToClone, int triggerX, int triggerY, bool MoveItem)
    {
        GameObject cloneObj = Instantiate(objToClone.gameObject);

        ObjectLoaderInfo objI;

        if (objToClone.GetComponent <NPC>() != null)
        {
            objI = ObjectLoader.newWorldObject(objToClone.item_id, objToClone.quality, objToClone.quality, objToClone.link, 2);
        }
        else
        {
            objI = ObjectLoader.newWorldObject(objToClone.item_id, objToClone.quality, objToClone.quality, objToClone.link, 256);
        }

        objI.instance = cloneObj.GetComponent <ObjectInteraction>();
        cloneObj.GetComponent <ObjectInteraction>().BaseObjectData = objI;
        objI.InUseFlag = 1;

        if (MoveItem)
        {
            if (this.gameObject.transform.position.x >= 100.0f)
            {            //If the object is off map use the triggerX and Y to calculate a suitable spawning point.
                /*cloneObj.transform.position = new Vector3(
                 *      (((float)triggerX) *1.2f + 0.6f),
                 *      (float)CurrentTileMap().GetFloorHeight(triggerX,triggerY)/6.666f,
                 *      (((float)triggerY) *1.2f  + 0.6f) */
                cloneObj.transform.position = CurrentTileMap().getTileVector(triggerX, triggerY);
                // );
            }
            else
            {
                Vector3 newpos = CurrentTileMap().getTileVector(triggerX, triggerY);
                cloneObj.transform.position = new Vector3(newpos.x, this.gameObject.transform.position.y, newpos.z);// this.gameObject.transform.position;
            }
        }


        cloneObj.transform.parent = objToClone.transform.parent;
        objI.instance.UpdatePosition();
        cloneObj.name = ObjectLoader.UniqueObjectName(objI);
        return(cloneObj);
    }
    public GameObject CloneObject(ObjectInteraction objToClone, int triggerX, int triggerY, bool MoveItem)
    {
        GameObject cloneObj = Instantiate(objToClone.gameObject);

        ObjectLoaderInfo objI;

        if (objToClone.GetComponent <NPC>() != null)
        {
            objI = ObjectLoader.newObject(objToClone.item_id, objToClone.quality, objToClone.quality, objToClone.link, 2);
        }
        else
        {
            objI = ObjectLoader.newObject(objToClone.item_id, objToClone.quality, objToClone.quality, objToClone.link, 256);
        }

        objI.instance = cloneObj.GetComponent <ObjectInteraction>();
        cloneObj.GetComponent <ObjectInteraction>().objectloaderinfo = objI;
        objI.InUseFlag = 1;

        if (MoveItem)
        {
            if (this.gameObject.transform.position.x >= 100.0f)
            {            //If the object is off map use the triggerX and Y to calculate a suitable spawning point.
                cloneObj.transform.position = new Vector3(
                    (((float)triggerX) * 1.2f + 0.6f),
                    (float)GameWorldController.instance.currentTileMap().GetFloorHeight(triggerX, triggerY) / 6.666f,
                    (((float)triggerY) * 1.2f + 0.6f)
                    );
            }
            else
            {
                cloneObj.transform.position = this.gameObject.transform.position;
            }
        }


        cloneObj.transform.parent = objToClone.transform.parent;
        objI.instance.UpdatePosition();
        cloneObj.name = ObjectLoader.UniqueObjectName(objI);
        return(cloneObj);
    }
/*
 * A change terrain trap changes a tile from one type to another. It works over a range of tiles that are set by the traps
 * x,y values. In Underworld these are set by the the relative position of the trap within the tile.
 * The tile it acts on is controlled by the trigger.
 *
 * Examples of it's usage
 * The Moonstone room on Level2
 * The path to the sword hilt on Level3
 *
 */

    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        Debug.Log(this.name);
        int textureQuality = (objInt().quality >> 1) & 0xf;

        for (short x = 0; x <= objInt().x; x++)
        {
            for (short y = 0; y <= objInt().y; y++)
            {
                short      tileXToChange = (short)(x + triggerX);
                short      tileYToChange = (short)(y + triggerY);
                GameObject tile          = GameWorldController.FindTile(tileXToChange, tileYToChange, TileMap.SURFACE_FLOOR);
                if (tile != null)
                {
                    TileInfo tileToChange = GameWorldController.instance.currentTileMap().Tiles[tileXToChange, tileYToChange];
                    //Destroy (tile);

                    switch (_RES)
                    {                            //I will probably have to change this again!
                    //case GAME_UW2:
                    //	tileToChange.floorTexture=textureQuality;
                    //	break;
                    default:
                        if (textureQuality < 10)
                        {
                            tileToChange.floorTexture = (short)textureQuality;                                  //+48;
                            //tileToChange.floorTexture=GameWorldController.instance.currentTileMap().texture_map[textureQuality+48];
                        }
                        break;
                    }

                    //currobj.zpos >> 2
                    //(objList[k].zpos >> 2);
                    tileToChange.Render = true;
                    for (int v = 0; v < 6; v++)
                    {
                        tileToChange.VisibleFaces[v] = true;
                    }
                    short tileTypeToChangeTo = (short)(objInt().quality & 0x01);
                    short newTileHeight      = (short)(objInt().zpos >> 2);
                    short newWallTexture     = tileToChange.wallTexture;
                    if (_RES == GAME_UW2)
                    {                            //Also the owner can be used to change wall texture. This means changing it's neighours.
                        if (objInt().owner < 63)
                        {
                            newWallTexture = objInt().owner;
                        }
                    }

                    //tileToChange.tileType=tileTypeToChangeTo;
                    tileToChange.DimX = 1;
                    tileToChange.DimY = 1;

                    ////tileToChange.floorHeight=newTileHeight;
                    //tileToChange.floorHeight=tileToChange.floorHeight;//DOUBLE CHECK THIS
                    tileToChange.isWater = TileMap.isTextureWater(GameWorldController.instance.currentTileMap().texture_map[tileToChange.floorTexture]);
                    //TileMapRenderer.RenderTile(GameWorldController.instance.LevelModel,tileXToChange,tileYToChange,tileToChange,tileToChange.isWater,false,false,true);
                    tileToChange.TileNeedsUpdate();
                    TileMapRenderer.UpdateTile(tileXToChange, tileYToChange, tileTypeToChangeTo, newTileHeight, tileToChange.floorTexture, newWallTexture, false);
                    Destroy(tile);

                    if (tileToChange.isDoor)
                    {                            //The door may be rendered
                        GameObject door = GameWorldController.findDoor(tileToChange.tileX, tileToChange.tileY);
                        if (door != null)
                        {
                            string doorname = ObjectLoader.UniqueObjectName(door.GetComponent <ObjectInteraction>().objectloaderinfo);
                            DestroyDoorPortion("front_leftside_" + doorname);
                            DestroyDoorPortion("front_over_" + doorname);
                            DestroyDoorPortion("front_rightside_" + doorname);
                            DestroyDoorPortion("side1_filler_" + doorname);
                            DestroyDoorPortion("over_filler_" + doorname);
                            DestroyDoorPortion("side2_filler_" + doorname);
                            DestroyDoorPortion("front_filler_" + doorname);
                            DestroyDoorPortion("rear_leftside_" + doorname);
                            DestroyDoorPortion("rear_over_" + doorname);
                            DestroyDoorPortion("rear_rightside_" + doorname);
                            DestroyDoorPortion(doorname);
                            TileMapRenderer.RenderDoorwayFront(
                                GameWorldController.instance.LevelModel,
                                GameWorldController.instance.currentTileMap(),
                                GameWorldController.instance.CurrentObjectList(),
                                door.GetComponent <ObjectInteraction>().objectloaderinfo
                                );
                            TileMapRenderer.RenderDoorwayRear(
                                GameWorldController.instance.LevelModel,
                                GameWorldController.instance.currentTileMap(),
                                GameWorldController.instance.CurrentObjectList(),
                                door.GetComponent <ObjectInteraction>().objectloaderinfo
                                );
                            Vector3 objPos = door.transform.position;
                            ObjectInteraction.CreateNewObject(GameWorldController.instance.currentTileMap(),
                                                              door.GetComponent <ObjectInteraction>().objectloaderinfo,
                                                              GameWorldController.instance.LevelModel, objPos
                                                              );
                        }
                    }
                }
                else
                {
                    Debug.Log(this.name + " Unable to find tile for change terrain trap " + tileXToChange + " " + tileYToChange);
                }
            }
        }

        GameWorldController.WorldReRenderPending = true;

        //	if ((objInt().owner<63) && (_RES==GAME_UW2))
        //	{
        //Now force re-render the tiles and their neighbours
        for (int x = -1; x <= objInt().x + 1; x++)
        {
            for (int y = -1; y <= objInt().y + 1; y++)
            {
                int tileXToChange = x + triggerX;
                int tileYToChange = y + triggerY;

                GameObject tile = GameWorldController.FindTile(tileXToChange, tileYToChange, TileMap.SURFACE_FLOOR);
                if (tile != null)
                {
                    Destroy(tile);
                }
                if ((tileXToChange >= 0) && (tileXToChange <= 63) && (tileYToChange >= 0) && (tileYToChange <= 63))
                {
                    TileInfo tileToChange = GameWorldController.instance.currentTileMap().Tiles[tileXToChange, tileYToChange];
                    tileToChange.Render = true;
                    for (int v = 0; v < 6; v++)
                    {
                        tileToChange.VisibleFaces[v] = true;
                    }
                    tileToChange.isWater = TileMap.isTextureWater(GameWorldController.instance.currentTileMap().texture_map[tileToChange.floorTexture]);
                    //TileMapRenderer.RenderTile(GameWorldController.instance.LevelModel,tileXToChange,tileYToChange,tileToChange,tileToChange.isWater,false,false,true);
                    tileToChange.TileNeedsUpdate();
                }
            }
        }
        //}
    }
    //Turns the item at index 995 in britannia castle into a specific item based on the skills of the player


    //TODO: disassembly has shown this is actually based on skills not class. FIX
    //Also probably the next item rather than specifically 995


    public override void ExecuteTrap(object_base src, int triggerX, int triggerY, int State)
    {
        if (this.next == 0)
        {
            Debug.Log("Hack Trap Class Item has no next!");
            return;
        }
        ObjectInteraction obj = ObjectLoader.getObjectIntAt(this.next);

        if (obj == null)
        {
            Debug.Log("Next item for hack trap item has no instance @" + this.next);
            return;
        }
        Destroy(obj.GetComponent <object_base>());//Remove object base from the existing item so it can be changed further on.


        //Get max magic skill score
        int MaxMagicSkillScore = Mathf.Max(UWCharacter.Instance.PlayerSkills.Casting, UWCharacter.Instance.PlayerSkills.ManaSkill);

        int  MaxCombatSkillScore = 0;
        byte CombatSkillType     = 0; //0=none, 1=sword, 2=axe, 3=mace; 4=missile, 5=unarmed.

        if (UWCharacter.Instance.PlayerSkills.Sword > MaxCombatSkillScore)
        {
            MaxCombatSkillScore = UWCharacter.Instance.PlayerSkills.Sword;
            CombatSkillType     = 1;
        }
        if (UWCharacter.Instance.PlayerSkills.Axe > MaxCombatSkillScore)
        {
            MaxCombatSkillScore = UWCharacter.Instance.PlayerSkills.Axe;
            CombatSkillType     = 2;
        }
        if (UWCharacter.Instance.PlayerSkills.Mace > MaxCombatSkillScore)
        {
            MaxCombatSkillScore = UWCharacter.Instance.PlayerSkills.Mace;
            CombatSkillType     = 3;
        }
        if (UWCharacter.Instance.PlayerSkills.Missile > MaxCombatSkillScore)
        {
            MaxCombatSkillScore = UWCharacter.Instance.PlayerSkills.Missile;
            CombatSkillType     = 4;
        }
        if (UWCharacter.Instance.PlayerSkills.Unarmed > MaxCombatSkillScore)
        {
            MaxCombatSkillScore = UWCharacter.Instance.PlayerSkills.Unarmed;
            CombatSkillType     = 5;
        }

        if ((MaxMagicSkillScore == 0) && (MaxCombatSkillScore == 0))
        {//Both scores are zero. Give a shield - they will need it!
            obj.item_id           = 60;
            obj.WorldDisplayIndex = 60;
            obj.InvDisplayIndex   = 60;
            obj.gameObject.AddComponent <Shield>();
        }
        else
        {
            if (MaxMagicSkillScore > MaxCombatSkillScore)
            {//magic is higher. Give a mani stone
                obj.item_id           = 244;
                obj.WorldDisplayIndex = 224;
                obj.InvDisplayIndex   = 244;
                obj.gameObject.AddComponent <RuneStone>();
            }
            else
            {//combat is higher give a item based on the skill type.
                switch (CombatSkillType)
                {
                case 1:     //shortsword
                    obj.item_id           = 4;
                    obj.WorldDisplayIndex = 4;
                    obj.InvDisplayIndex   = 4;
                    obj.gameObject.AddComponent <WeaponMelee>();
                    break;

                case 2:     //hand axe/
                    obj.item_id           = 0;
                    obj.WorldDisplayIndex = 0;
                    obj.InvDisplayIndex   = 0;
                    obj.gameObject.AddComponent <WeaponMelee>();
                    break;

                case 3:     //cudgel
                    obj.item_id           = 7;
                    obj.WorldDisplayIndex = 7;
                    obj.InvDisplayIndex   = 7;
                    obj.gameObject.AddComponent <WeaponMelee>();
                    break;

                case 4:     // supply of slingstones
                    obj.item_id           = 16;
                    obj.WorldDisplayIndex = 16;
                    obj.InvDisplayIndex   = 16;
                    obj.isquant           = 1;
                    obj.link = 10;
                    obj.gameObject.AddComponent <object_base>();
                    break;

                default:     //unarmed/gloves
                    obj.item_id           = 38;
                    obj.WorldDisplayIndex = 38;
                    obj.InvDisplayIndex   = 38;
                    obj.gameObject.AddComponent <Gloves>();
                    break;
                }
            }
        }

        obj.gameObject.name = ObjectLoader.UniqueObjectName(obj.BaseObjectData);
        obj.UpdateAnimation();

        //switch (UWCharacter.Instance.CharClass)
        //{
        //    //Gloves
        //    case UWCharacter.CharClassFighter://fighter
        //        obj.item_id = 38;
        //        obj.WorldDisplayIndex = 38;
        //        obj.InvDisplayIndex = 38;
        //        obj.gameObject.AddComponent<Gloves>();
        //        break;
        //    //Mani stone
        //    case UWCharacter.CharClassMage://mage
        //    case UWCharacter.CharClassBard://bard
        //    case UWCharacter.CharClassDruid://Druid
        //    case UWCharacter.CharClassShepard://shepherd
        //        obj.item_id = 244;
        //        obj.WorldDisplayIndex = 224;
        //        obj.InvDisplayIndex = 244;
        //        obj.gameObject.AddComponent<RuneStone>();
        //        break;
        //    //Shortsword
        //    case UWCharacter.CharClassTinker://tinker
        //    case UWCharacter.CharClassPaladin://paladin
        //        obj.item_id = 4;
        //        obj.WorldDisplayIndex = 4;
        //        obj.InvDisplayIndex = 4;
        //        obj.gameObject.AddComponent<WeaponMelee>();
        //        break;
        //    //Shield
        //    case UWCharacter.CharClassRanger://ranger
        //        obj.item_id = 60;
        //        obj.WorldDisplayIndex = 60;
        //        obj.InvDisplayIndex = 60;
        //        obj.gameObject.AddComponent<Shield>();
        //        break;
        //}
    }