Line data Source code
1 : function ResourceDropsite() {} 2 : 3 2 : ResourceDropsite.prototype.Schema = 4 : "<element name='Types'>" + 5 : "<list>" + 6 : "<zeroOrMore>" + 7 : Resources.BuildChoicesSchema() + 8 : "</zeroOrMore>" + 9 : "</list>" + 10 : "</element>" + 11 : "<element name='Sharable' a:help='Allows allies to use this entity.'>" + 12 : "<data type='boolean'/>" + 13 : "</element>"; 14 : 15 2 : ResourceDropsite.prototype.Init = function() 16 : { 17 2 : this.sharable = this.template.Sharable == "true"; 18 2 : this.shared = this.sharable; 19 : }; 20 : 21 : /** 22 : * Returns the list of resource types accepted by this dropsite, 23 : * as defined by it being referred to in the template and the resource being enabled. 24 : */ 25 2 : ResourceDropsite.prototype.GetTypes = function() 26 : { 27 5 : let types = ApplyValueModificationsToEntity("ResourceDropsite/Types", this.template.Types, this.entity); 28 5 : return types.split(/\s+/); 29 : }; 30 : 31 : /** 32 : * Returns whether this dropsite accepts the given generic type of resource. 33 : */ 34 2 : ResourceDropsite.prototype.AcceptsType = function(type) 35 : { 36 5 : return this.GetTypes().indexOf(type) != -1; 37 : }; 38 : 39 : /** 40 : * @param {Object} resources - The resources to drop here in the form of { "resource": amount }. 41 : * @param {number} entity - The entity that tries to drop their resources here. 42 : * 43 : * @return {Object} - Which resources could be dropped off here. 44 : */ 45 2 : ResourceDropsite.prototype.ReceiveResources = function(resources, entity) 46 : { 47 3 : let cmpPlayer = QueryOwnerInterface(entity); 48 3 : if (!cmpPlayer) 49 0 : return {}; 50 : 51 3 : let taken = {}; 52 3 : for (let type in resources) 53 5 : if (this.AcceptsType(type)) 54 3 : taken[type] = resources[type]; 55 : 56 3 : cmpPlayer.AddResources(taken); 57 3 : return taken; 58 : }; 59 : 60 2 : ResourceDropsite.prototype.IsSharable = function() 61 : { 62 1 : return this.sharable; 63 : }; 64 : 65 2 : ResourceDropsite.prototype.IsShared = function() 66 : { 67 0 : return this.shared; 68 : }; 69 : 70 2 : ResourceDropsite.prototype.SetSharing = function(value) 71 : { 72 0 : if (!this.sharable) 73 0 : return; 74 0 : this.shared = value; 75 0 : Engine.PostMessage(this.entity, MT_DropsiteSharingChanged, { "shared": this.shared }); 76 : }; 77 : 78 2 : Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite);