Modul:WeaponSubobjects

Aus Star Citizen Wiki
Modul Dokumentation[view][edit][history][purge]
Diese Dokumentation wird von Modul:WeaponSubobjects/doc aus übernommen. Änderungen können auf der Diskussionsseite vorgeschlagen werden.

Dieses Modul stellt Funktionalitäten für Waffen bereit.

Erlaubt das Speichern von Schadensarten, Feuermodi, Munition und Hardpoints von Fahrzeugwaffen und Handfeuerwaffen.

Zusätzlich können auch die gespeicherten Daten abgerufen werden.

Öffentliche Methoden

Das Modul stellt folgende öffentliche Methoden bereit:

  • setSemanticProperties( data )
    • Speichert alle verfügbaren Daten als Subobjekte
  • getWeaponModes( name )
    • Rückgabe aller verfügbaren Feuermodi einer Waffe
  • getDefaultAttachments( name )
    • Rückgabe aller der Standardausrüstung einer Waffe
  • getAttachmentPorts( name )
    • Rückgabe aller verfügbaren Hardpoints einer Waffe
  • getDamages( name )
    • Rückgabe aller verfügbaren Schadensarten einer Waffe
  • getAmmunition( name )
    • Rückgabe aller verfügbaren Munitionen einer Waffe

local WeaponSubobjects = {}

local metatable = {}
local methodtable = {}

metatable.__index = methodtable


--- Translate attachment port position to german text
local attachmentPositionTranslations = {
    [ 'Optics' ]      = 'Optik',
    [ 'Barrel' ]      = 'Lauf',
    [ 'Underbarrel' ] = 'Unterlauf',
    [ 'Magazine' ]    = 'Magazin',
}


--- Translate weapon type to german text
local damageTranslations = {
    [ 'physical' ] = 'Physikalisch',
    [ 'energy' ]   = 'Energie',
}


--- @param position string
--- @return string
local function translateAttachmentPosition( position )
    return {
        de_DE = ( attachmentPositionTranslations[ position ] or position ),
        en_EN = position,
    }
end


--- @param position string
--- @return string
local function translateDamages( damage )
    return {
        de_DE = ( damageTranslations[ damage ] or damage ),
        en_EN = damage,
    }
end


--- Query the weapon fire mode subobjects for this page
--- @param name string
--- @return table
function methodtable.getWeaponModes( self, name )
    local query = {
        '[[-Has subobject::' .. name .. ']][[Feuerrate::+]]',
        '?Name#-=name',
        '?Feuerrate#-=rof',
        '?Schaden pro Sekunde#-=dps',
        '?Munition pro Schuss#-=mps',
        '?Kugel pro Schuss#-=bps',
        'mainlabel=-'
    }

    return mw.smw.ask( query )
end


--- Query the default weapon attachment (the default loadout) subobjects for this page
--- @param name string
--- @return table
function methodtable.getDefaultAttachments( self, name )
    local query = {
        '[[-Has subobject::' .. name .. ']][[Typ::Standardausrüstung]]',
        '?Name#-=name',
        '?Position=position', '+lang=' .. self.common.getLocaleForPage(),
        '?Größe#-=size',
        '?Grad#-=grade',
        'mainlabel=-'
    }

    return mw.smw.ask( query )
end


--- Query the weapon attachment subobjects for this page
--- @param name string
--- @return table
function methodtable.getAttachmentPorts( self, name )
    local query = {
        '[[-Has subobject::' .. name .. ']][[Typ::Waffenbefestigung]]',
        '?Name#-=name',
        '?Position=position', '+lang=' .. self.common.getLocaleForPage(),
        '?Position=position_de', '+lang=de',
        '?Minimalgröße#-=min_size',
        '?Maximalgröße#-=max_size',
        'mainlabel=-'
    }

    return mw.smw.ask( query )
end


--- Query the weapon damage subobjects for this page
--- Each damage is a separate subobject
--- @param name string
--- @return table
function methodtable.getDamages( self, name )
    local query = {
        '[[-Has subobject::' .. name .. ']][[Schaden::+]][[Typ::+]]',
        '?Schadensart#-=name',
        '?Typ=type', '+lang=' .. self.common.getLocaleForPage(),
        '?Schaden#-=damage',
        'mainlabel=-'
    }

    return mw.smw.ask( query )
end

--- Query the weapon ammunition subobjects for this page
--- In the future a weapon may have multiple ammunitions, hence we save it as a subobject
--- @param name string
--- @return table
function methodtable.getAmmunition( self, name )
    local query = {
        '[[-Has subobject::' .. name .. ']][[Mündungsgeschwindigkeit::+]]',
        '?Größe#-=size',
        '?Lebenszeit#-=lifetime',
        '?Mündungsgeschwindigkeit#-=muzzle_velocity',
        '?Maximalreichweite#-=max_range',
        'mainlabel=-'
    }

    return mw.smw.ask( query )
end


--- Base Properties that are shared across all weapons
--- Uses the following keys:
--- * ammunition
--- * damages
--- * attachmentPorts
--- * attachments
--- * modes
--- @return void
function methodtable.setSemanticProperties( self, data )
    -- Api Error, don't set anything
    if data == nil or type( data ) ~= 'table' or data .personal_weapon == nil then
        return
    end

    if data.personal_weapon.ammunition ~= nil then
        local muzzleVelocity = data.personal_weapon.ammunition.speed or nil
        if muzzleVelocity ~= nil then
            muzzleVelocity = self.common.formatNum( muzzleVelocity ) .. 'm/s'
        end

        mw.smw.subobject( {
            [ 'Größe' ]                   = data.personal_weapon.ammunition.size or nil,
            [ 'Lebenszeit' ]              = self.common.formatNum( data.personal_weapon.ammunition.lifetime or nil, nil ),
            [ 'Mündungsgeschwindigkeit' ] = muzzleVelocity,
            [ 'Maximalreichweite' ]       = self.common.formatNum( data.personal_weapon.ammunition.range or nil, nil ),
        }, 'Munition' )
    end

    if data.personal_weapon.damages ~= nil and type( data.personal_weapon.damages ) == 'table' then
        for _, damage in pairs( data.personal_weapon.damages ) do
            if damage.name ~= nil then
                mw.smw.subobject( {
                    [ 'Schadensart' ] = damage.name,
                    [ 'Typ' ]         = self.common.mapTranslation( translateDamages( damage.type ) ),
                    [ 'Schaden' ]     = self.common.formatNum( damage.damage or nil, nil ),
                } )
            end
        end
    end

    if data.ports ~= nil and type( data.ports ) == 'table' then
        for _, attachment in pairs( data.ports ) do
            if attachment.display_name ~= nil then
                mw.smw.subobject( {
                    [ 'Name' ]         = attachment.display_name,
                    [ 'Position' ]     = self.common.mapTranslation( translateAttachmentPosition( attachment.position or nil ) ),
                    [ 'Minimalgröße' ] = attachment.sizes.min or nil,
                    [ 'Maximalgröße' ] = attachment.sizes.max or nil,
                    [ 'Typ' ]          = {
                        'Waffenbefestigung@de',
                        'Weapon Attachment@en',
                    },
                }, attachment.display_name )
                
                if type( attachment.equipped_item ) == 'table' then
	                mw.smw.subobject( {
	                    [ 'Name' ]     = attachment.equipped_item.name,
	                    [ 'Position' ] = self.common.mapTranslation( translateAttachmentPosition( attachment.position or nil ) ),
	                    [ 'Größe' ]    = attachment.equipped_item.size or nil,
	                    [ 'Grad' ]     = attachment.equipped_item.grade or nil,
	                    [ 'Typ' ]      = {
	                        'Standardausrüstung@de',
	                        'Standard Equipment@en',
	                    },
	                }, attachment.equipped_item.name )
            	end
            end
        end
    end

    if data.personal_weapon.modes ~= nil and type( data.personal_weapon.modes ) == 'table' then
        for _, mode in pairs( data.personal_weapon.modes ) do
            if mode.mode ~= nil and string.match( mode.mode, 'Test' ) == nil then
                mw.smw.subobject( {
                    [ 'Name' ]                = mode.mode,
                    [ 'Feuerrate' ]           = self.common.formatNum( mode.rpm or nil, nil ),
                    [ 'Schaden pro Sekunde' ] = self.common.formatNum( mode.damage_per_second or nil ),
                    [ 'Munition pro Schuss' ] = self.common.formatNum( mode.ammo_per_shot or nil, nil ),
                    [ 'Kugel pro Schuss' ]    = self.common.formatNum( mode.pellet_per_shot or nil, nil ),
                }, mode.mode )
            end
        end
    end
end


--- New Instance
function WeaponSubobjects.new( self )
    local instance = {
        categories = {},

        -- Extensions
        common = require( 'Module:Common' ),
    }

    setmetatable( instance, metatable )

    return instance
end

return WeaponSubobjects
Cookies helfen uns bei der Bereitstellung dieses Wikis. Durch die Nutzung des Star Citizen Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.