private void OnDestroy() { if ((!destroyable && !pickupable) || (this.GetComponent <Entity>() != null && this.GetComponent <Entity>().isAlive)) { return; } // -- gather object level if it is an entity int level = 0; Entity m = this.GetComponent <Entity>(); if (m) { level = m.level; } int id = 0; UCE_PlaceableObject po = this.gameObject.GetComponent <UCE_PlaceableObject>(); if (po) { id = po.id; } // -- delete from database Database.singleton.UCE_DeletePlaceableObject(ownerCharacter, ownerGuild, level, itemName, id); }
// ----------------------------------------------------------------------------------- // UCE_CanUpgradePlaceableObject // ----------------------------------------------------------------------------------- public bool UCE_CanUpgradePlaceableObject(UCE_PlaceableObject po) { if (po) { Entity e = po.GetComponent <Entity>(); if (e != null) { UCE_PlaceableObjectUpgradeCost c = po.getUpgradeCost(e.level); if (c != null) { if (level >= c.minLevel && gold >= c.gold && coins >= c.coins && UCE_checkHasAllItems(c) ) { return(true); } } } } return(false); }
private void Update() { Player player = Player.localPlayer; if (!player) { return; } // -- check for click if (UCE_Tools.UCE_SelectionHandling(this.gameObject)) { UCE_PlaceableObject po = this.gameObject.GetComponent <UCE_PlaceableObject>(); if (po != null && po.ownerCharacter == player.name ) { player.UCE_myPlaceableObject = po; if (!_UCE_UI_PlaceableObject) { _UCE_UI_PlaceableObject = FindObjectOfType <UCE_UI_PlaceableObject>(); } _UCE_UI_PlaceableObject.Show(); } } }
// ----------------------------------------------------------------------------------- // SpawnRTSStructures // ----------------------------------------------------------------------------------- protected IEnumerator SpawnRTSStructures() { List <List <object> > table = Database.singleton.UCE_LoadPlaceableObjects(); foreach (List <object> row in table) { string itemName = (string)row[9]; if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject) { Vector3 v = new Vector3( (float)row[2], (float)row[3], (float)row[4]); Quaternion rotation = Quaternion.Euler((float)row[5], (float)row[6], (float)row[7]); GameObject go = (GameObject)Instantiate(((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject, v, rotation); UCE_PlaceableObject po = go.GetComponent <UCE_PlaceableObject>(); if (po) { po.permanent = true; po.ownerCharacter = (string)row[0]; po.ownerGuild = (string)row[1]; po.itemName = itemName; // row 9 #if _SQLITE po.id = Convert.ToInt32((long)row[10]); #elif _MYSQL po.id = (int)row[10]; #endif Entity e = po.GetComponent <Entity>(); if (e) { #if _SQLITE e.level = Convert.ToInt32((long)row[8]); #elif _MYSQL e.level = (int)row[8]; #endif } } NetworkServer.Spawn(go); } } yield return(new WaitForEndOfFrame()); }
public void Target_UCE_StartUpgradePlaceableObjectClient(NetworkConnection target, NetworkIdentity ni) { if (ni != null) { UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>(); Entity e = po.GetComponent<Entity>(); if (e != null) { LookAtY(po.gameObject.transform.position); UCE_myPlaceableObject = po; UCE_setTimer(po.getUpgradeCost(e.level).duration); UCE_CastbarShow(UCE_MSG_PLACEABLEOBJECT_UPGRADE, po.getUpgradeCost(e.level).duration); } } }
// ----------------------------------------------------------------------------------- // Cmd_CancelSpawnPlaceableObject // @Client // ----------------------------------------------------------------------------------- public void UCE_CancelSpawnPlaceableObject() { if (UCE_BuildSystem_PreviewObject != null) Destroy(UCE_BuildSystem_PreviewObject); if (UCE_BuildSystem_GridObject != null) Destroy(UCE_BuildSystem_GridObject); UCE_BuildSystem_PreviewObject = null; UCE_myPlaceableObject = null; UCE_myPlaceableObjectItem = null; UCE_removeTask(); UCE_stopTimer(); UCE_CastbarHide(); Destroy(indicator); }
// ----------------------------------------------------------------------------------- // checkBuildSystem // ----------------------------------------------------------------------------------- #if _iMMOBUILDSYSTEM public bool checkBuildSystem(Player player) { if (!parent || !parent.GetComponentInParent <UCE_PlaceableObject>()) { return(true); } UCE_PlaceableObject po = parent.GetComponentInParent <UCE_PlaceableObject>(); if (po == null || (!ownerCharacterOnly && !ownerGuildOnly)) { return(true); } return ((!ownerCharacterOnly || (!reverseCheck && ownerCharacterOnly && player.name == po.ownerCharacter || reverseCheck && ownerCharacterOnly && player.name != po.ownerCharacter)) && (!ownerGuildOnly || (!reverseCheck && ownerGuildOnly && player.guild.name == po.ownerGuild || reverseCheck && ownerGuildOnly && player.guild.name != po.ownerGuild))); }
public void Cmd_UCE_StartUpgradePlaceableObject(NetworkIdentity ni) { if (ni != null) { UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>(); if (UCE_CanUpgradePlaceableObject(po)) { Entity e = po.GetComponent<Entity>(); if (e != null) { UCE_addTask(); UCE_myPlaceableObject = po; UCE_setTimer(po.getUpgradeCost(e.level).duration); Target_UCE_StartUpgradePlaceableObjectClient(connectionToClient, ni); } } } }
protected IEnumerator SpawnPlaceableObject() { UCE_PlaceableObject o = null; int level = 0; Vector3 vBuildPosition = UCE_getSpawnDestination(); if (UCE_myPlaceableObjectItem.placementObject) { GameObject SimpleObject = (GameObject)Instantiate(UCE_myPlaceableObjectItem.placementObject, vBuildPosition, Quaternion.identity); NetworkServer.Spawn(SimpleObject); o = SimpleObject.GetComponent <UCE_PlaceableObject>(); if (o) { o.permanent = UCE_myPlaceableObjectItem.isPermanent; o.ownerCharacter = this.name; o.ownerGuild = this.guild.name; o.itemName = UCE_myPlaceableObjectItem.name; Entity e = SimpleObject.GetComponent <Entity>(); if (e) { level = e.level; } } } if (o != null && UCE_myPlaceableObjectItem.isPermanent) { Database.singleton.UCE_SavePlaceableObject(this.name, this.guild.name, o.gameObject, level, UCE_myPlaceableObjectItem.name, o.id); } InventoryRemove(new Item(UCE_myPlaceableObjectItem), UCE_myPlaceableObjectItem.decreaseAmount); UCE_myPlaceableObjectItem = null; yield return(new WaitForEndOfFrame()); }
// ----------------------------------------------------------------------------------- // UCE_checkBuildSystem // ----------------------------------------------------------------------------------- #if _iMMOBUILDSYSTEM public bool UCE_checkBuildSystem(Entity target) { UCE_PlaceableObject po = GetComponentInParent <UCE_PlaceableObject>(); if (po == null) { return(false); } if (!(target is Player) || (!dontAttackOwner && !dontAttackOwnerParty && !dontAttackOwnerGuild)) { return(true); } Player player = (Player)target; return ((!dontAttackOwner || (dontAttackOwner && player.name == po.ownerCharacter)) && (!dontAttackOwnerParty || (dontAttackOwnerParty && player.InParty() && player.party.Contains(po.ownerCharacter))) && (!dontAttackOwnerGuild || (dontAttackOwnerGuild && player.guild.name == po.ownerGuild))); }
public void Cmd_UCE_UnspawnPlaceableObject(NetworkIdentity ni) { if (ni != null) { UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>(); Entity e = po.GetComponent<Entity>(); if (po && po.pickupable && po.ownerCharacter == this.name ) { LookAtY(po.gameObject.transform.position); ScriptableItem item; if (ScriptableItem.dict.TryGetValue(po.itemName.GetStableHashCode(), out item)) { // -- enough inventory space? Item result = new Item(item); if (InventoryCanAdd(result, ((UCE_Item_PlaceableObject)item).decreaseAmount)) { // -- delete object from database Database.singleton.UCE_DeletePlaceableObject(this.name, this.guild.name, e.level, po.itemName, po.id); // -- add it back to the inventory again InventoryAdd(new Item(item), ((UCE_Item_PlaceableObject)item).decreaseAmount); // -- remove the object NetworkServer.Destroy(po.gameObject); } } } } }
// ------------------------------------------------------------------------------- // OnTriggerEnter // ------------------------------------------------------------------------------- private void OnTriggerEnter(Collider co) { string areaOwnerName = ""; string areaGuildName = ""; Player e = co.GetComponentInParent <Player>(); if (e != null && isActive) { UCE_PlaceableObject o = GetComponent <UCE_PlaceableObject>(); if (o && o.ownerCharacter != "") { areaOwnerName = o.ownerCharacter; } if (o && o.ownerGuild != "") { areaGuildName = o.ownerGuild; } e.UCE_SetPlaceableObjectArea(areaId, areaOwnerName, areaGuildName, true); } }
// ----------------------------------------------------------------------------------- // SpawnRTSStructures // ----------------------------------------------------------------------------------- protected IEnumerator SpawnRTSStructures() { #if _SERVER var table = Database.singleton.UCE_LoadPlaceableObjects(); foreach (var row in table) { #if _SQLITE string itemName = row.item; if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject) { Vector3 v = new Vector3(row.x, row.y, row.z); Quaternion rotation = Quaternion.Euler(row.xRot, row.yRot, row.zRot); #elif _MYSQL string itemName = (string)row[9]; if (((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject) { Vector3 v = new Vector3( (float)row[2], (float)row[3], (float)row[4]); Quaternion rotation = Quaternion.Euler((float)row[5], (float)row[6], (float)row[7]); #endif GameObject go = (GameObject)Instantiate(((UCE_Item_PlaceableObject)ScriptableItem.dict[itemName.GetStableHashCode()]).placementObject, v, rotation); UCE_PlaceableObject po = go.GetComponent <UCE_PlaceableObject>(); if (po) { po.permanent = true; po.itemName = itemName; // row 9 #if _SQLITE po.ownerCharacter = row.character; po.ownerGuild = row.guild; po.id = row.id; #elif _MYSQL po.ownerCharacter = (string)row[0]; po.ownerGuild = (string)row[1]; po.id = (int)row[10]; #endif Entity e = po.GetComponent <Entity>(); if (e) { #if _SQLITE e.level = row.level; #elif _MYSQL e.level = (int)row[8]; #endif } } NetworkServer.Spawn(go); } } #endif yield return(new WaitForEndOfFrame()); } // ----------------------------------------------------------------------------------- }